-
Notifications
You must be signed in to change notification settings - Fork 30.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: deprecate closing FileHandle on garbage collection
Closing the FileHandle on garbage collection is a bad practice. Runtime deprecate and indicate that an error will be thrown in the future. PR-URL: #28396 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
- Loading branch information
Showing
6 changed files
with
102 additions
and
2 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
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,39 @@ | ||
// Flags: --expose-gc --no-warnings | ||
'use strict'; | ||
|
||
// Test that a runtime warning is emitted when a FileHandle object | ||
// is allowed to close on garbage collection. In the future, this | ||
// test should verify that closing on garbage collection throws a | ||
// process fatal exception. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const { promises: fs } = require('fs'); | ||
|
||
const warning = | ||
'Closing a FileHandle object on garbage collection is deprecated. ' + | ||
'Please close FileHandle objects explicitly using ' + | ||
'FileHandle.prototype.close(). In the future, an error will be ' + | ||
'thrown if a file descriptor is closed during garbage collection.'; | ||
|
||
async function doOpen() { | ||
const fh = await fs.open(__filename); | ||
|
||
common.expectWarning({ | ||
Warning: [[`Closing file descriptor ${fh.fd} on garbage collection`]], | ||
DeprecationWarning: [[warning, 'DEP00XX']] | ||
}); | ||
|
||
return fh; | ||
} | ||
|
||
// Perform the file open assignment within a block. | ||
// When the block scope exits, the file handle will | ||
// be eligible for garbage collection. | ||
{ | ||
doOpen().then(common.mustCall((fd) => { | ||
assert.strictEqual(typeof fd, 'object'); | ||
})); | ||
} | ||
|
||
setTimeout(() => global.gc(), 10); |