-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Do not set the fd as a property on the native object. - Use the already-existent `GetFD()` method to pass the fd from C++ to JS. - Cache the fd in JS to avoid repeated accesses to the C++ getter. - Set the fd to `-1` after close, thus reliably making subsequent calls using the `FileHandle` return `EBADF`. Fixes: #31361 PR-URL: #31389 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Minwoo Jung <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: Rich Trott <[email protected]>
- Loading branch information
1 parent
0bafb5c
commit 32ac1be
Showing
4 changed files
with
33 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const fs = require('fs').promises; | ||
|
||
(async () => { | ||
const filehandle = await fs.open(__filename); | ||
|
||
assert.notStrictEqual(filehandle.fd, -1); | ||
await filehandle.close(); | ||
assert.strictEqual(filehandle.fd, -1); | ||
|
||
// Open another file handle first. This would typically receive the fd | ||
// that `filehandle` previously used. In earlier versions of Node.js, the | ||
// .stat() call would then succeed because it still used the original fd; | ||
// See https://github.com/nodejs/node/issues/31361 for more details. | ||
const otherFilehandle = await fs.open(process.execPath); | ||
|
||
assert.rejects(() => filehandle.stat(), { | ||
code: 'EBADF', | ||
syscall: 'fstat' | ||
}); | ||
|
||
await otherFilehandle.close(); | ||
})().then(common.mustCall()); |