Skip to content

Commit 11d366b

Browse files
Update doc/api/deprecations.md
Co-authored-by: Livia Medeiros <livia@cirno.name>
1 parent eff7db9 commit 11d366b

File tree

4 files changed

+22
-20
lines changed

4 files changed

+22
-20
lines changed

doc/api/deprecations.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2866,7 +2866,7 @@ To maintain existing behavior `response.finished` should be replaced with
28662866
<!-- YAML
28672867
changes:
28682868
- version: REPLACEME
2869-
pr-url: https://github.com/nodejs/node/pull/00000
2869+
pr-url: https://github.com/nodejs/node/pull/58536
28702870
description: End-of-Life.
28712871
- version: v14.0.0
28722872
pr-url: https://github.com/nodejs/node/pull/28396

src/base_object-inl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ v8::Global<v8::Object>& BaseObject::persistent() {
4949

5050

5151
v8::Local<v8::Object> BaseObject::object() const {
52-
return PersistentToLocal::Default(env()->isolate(), persistent_handle_);
52+
return PersistentToLocal::Default(env()->isolate(), persistent_handle_); 
5353
}
5454

5555
v8::Local<v8::Object> BaseObject::object(v8::Isolate* isolate) const {

src/node_file.cc

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -350,32 +350,34 @@ inline void FileHandle::Close() {
350350

351351
AfterClose();
352352

353-
if (ret < 0) {
354-
// Do not unref this
355-
env()->SetImmediate([detail](Environment* env) {
353+
// Even though we closed the file descriptor, we still throw an error
354+
// if the FileHandle object was not closed before garbage collection.
355+
// Because this method is called during garbage collection, we will defer
356+
// throwing the error until the next immediate queue tick so as not
357+
// to interfere with the gc process.
358+
//
359+
// This exception will end up being fatal for the process because
360+
// it is being thrown from within the SetImmediate handler and
361+
// there is no JS stack to bubble it to. In other words, tearing
362+
// down the process is the only reasonable thing we can do here.
363+
env()->SetImmediate([detail](Environment* env) {
364+
HandleScope handle_scope(env->isolate());
365+
366+
// If there was an error while trying to close the file descriptor,
367+
// we will throw that instead.
368+
if (detail.ret < 0) {
356369
char msg[70];
357370
snprintf(msg, arraysize(msg),
358371
"Closing file descriptor %d on garbage collection failed",
359372
detail.fd);
360-
// This exception will end up being fatal for the process because
361-
// it is being thrown from within the SetImmediate handler and
362-
// there is no JS stack to bubble it to. In other words, tearing
363-
// down the process is the only reasonable thing we can do here.
364373
HandleScope handle_scope(env->isolate());
365374
env->ThrowUVException(detail.ret, "close", msg);
366-
});
367-
return;
368-
}
375+
return;
376+
}
369377

370-
// Even though we closed the file descriptor, we still throw an error
371-
// if the FileHandle object was not closed before garbage collection.
372-
// Because this method is called during garbage collection, we will defer
373-
// throwing the error until the next immediate queue tick so as not
374-
// to interfere with the gc process.
375-
env()->SetImmediate([](Environment* env) {
376378
THROW_ERR_INVALID_STATE(
377379
env,
378-
"FileHandle object was not closed before garbage collection. "
380+
"A FileHandle object was closed during garbage collection. "
379381
"This used to be allowed with a deprecation warning but is now "
380382
"considered an error. Please close FileHandle objects explicitly.");
381383
});

test/parallel/test-fs-filehandle.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const { stringToFlags } = require('internal/fs/utils');
1212
// error is thrown if it is not closed.
1313
process.on('uncaughtException', common.mustCall((err) => {
1414
assert.strictEqual(err.code, 'ERR_INVALID_STATE');
15-
assert.match(err.message, /^FileHandle object was not closed/);
15+
assert.match(err.message, /^A FileHandle object was closed during/);
1616
}));
1717

1818

0 commit comments

Comments
 (0)