-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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 <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- 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()); |