Skip to content

Commit

Permalink
worker: fix stream racing with terminate
Browse files Browse the repository at this point in the history
`OnStreamAfterReqFinished` uses `v8::Object::Has` to check if it needs
to call `oncomplete`. `v8::Object::Has` needs to execute Javascript.
However when worker threads are involved, `OnStreamAfterReqFinished` may
be called after the worker thread termination has begun via
`worker.terminate()`. This makes `v8::Object::Has` return `Nothing`,
which triggers an assert.

This diff fixes the issue by simply defaulting us to `false` in the case
where `Nothing` is returned. This is sound because we can't execute
`oncomplete` anyway as the isolate is terminating.

Fixes: nodejs#38418
  • Loading branch information
airtable-keyhanvakil committed Apr 26, 2022
1 parent 4f9bc41 commit ce6ca47
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/stream_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,8 @@ void ReportWritesToJSStreamListener::OnStreamAfterReqFinished(
stream->ClearError();
}

if (req_wrap_obj->Has(env->context(), env->oncomplete_string()).FromJust())
if (req_wrap_obj->Has(env->context(), env->oncomplete_string())
.FromMaybe(false))
async_wrap->MakeCallback(env->oncomplete_string(), arraysize(argv), argv);
}

Expand Down

0 comments on commit ce6ca47

Please sign in to comment.