Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

worker: spin uv_run twice before closing loop #26138

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/node_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ class WorkerThreadData {

isolate->Dispose();

// Need to run the loop one more time to close the platform's uv_async_t
// Need to run the loop twice more to close the platform's uv_async_t
// TODO(addaleax): It would be better for the platform itself to provide
// some kind of notification when it has fully cleaned up.
uv_run(&loop_, UV_RUN_ONCE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be in a #ifdef Win32 or similar?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not UV_RUN_DEFAULT? My concern is that some platform-specific libuv change may at some point require a different arbitrary number or runs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eugeneo Because we want to not keep spinning the event loop indefinitely, which could happen if e.g. addons still have active handles (which we currently crash for, which is what we want).

I agree that this is hacky – hence the TODO – but I wouldn’t expect libuv to change anything here (and if they do, we’d notice because they run Node.js in the libuv CI).

@Fishrock123 I don’t have strong feelings about that, I can add it if you want.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should keep the behavior consistent then.

uv_run(&loop_, UV_RUN_ONCE);

CheckedUvLoopClose(&loop_);
Expand Down