Skip to content

Commit 8f8e71a

Browse files
committed
src: fix crash on FSReqPromise destructor
We are deciding whether to end `fs` promises by checking `can_call_into_js()` whereas in the `FSReqPromise` destructor we're using the `is_stopping()` check. Though this may look as semantically correct it has issues because though both values are modified before termination on `Environment::ExitEnv()` and both are atomic they are not syncronized together so it may happen that when reaching the destructor `call_into_js` may be set to `false` whereas `is_stopping` remains `false` causing the crash. Fix this by using the same checks everywhere. Fixes: #43499
1 parent b970634 commit 8f8e71a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/node_file.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ MaybeLocal<Promise> FileHandle::ClosePromise() {
377377
std::unique_ptr<CloseReq> close(CloseReq::from_req(req));
378378
CHECK_NOT_NULL(close);
379379
close->file_handle()->AfterClose();
380-
if (!close->env()->can_call_into_js()) return;
380+
if (close->env()->is_stopping()) return;
381381
Isolate* isolate = close->env()->isolate();
382382
if (req->result < 0) {
383383
HandleScope handle_scope(isolate);
@@ -651,7 +651,7 @@ void FSReqAfterScope::Reject(uv_fs_t* req) {
651651
}
652652

653653
bool FSReqAfterScope::Proceed() {
654-
if (!wrap_->env()->can_call_into_js()) {
654+
if (wrap_->env()->is_stopping()) {
655655
return false;
656656
}
657657

0 commit comments

Comments
 (0)