fix: prevent createDeferred from keeping Node.js process alive#2588
Open
veeceey wants to merge 2 commits intosolidjs:mainfrom
Open
fix: prevent createDeferred from keeping Node.js process alive#2588veeceey wants to merge 2 commits intosolidjs:mainfrom
veeceey wants to merge 2 commits intosolidjs:mainfrom
Conversation
The scheduler uses MessageChannel internally for task scheduling. In Node.js (with -C browser flag), active MessagePort listeners keep the event loop alive even after all work is done and dispose() has been called. This causes the process to hang indefinitely. The fix calls unref() on both MessageChannel ports so they don't prevent natural process exit. The unref method is Node.js-specific and doesn't exist in browsers, so we guard the call with a typeof check. Fixes solidjs#2570
🦋 Changeset detectedLatest commit: 89c39c9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2570
When using
createDeferredin Node.js (vianode -C browser), the process hangs after all work is done because the internalMessageChannelkeeps the event loop alive. The scheduler creates aMessageChannelfor task scheduling, and in Node.js, activeMessagePortlisteners prevent the process from exiting.The fix calls
unref()on both ports right after creating the channel. This tells Node.js not to keep the process alive solely because of these ports. In browsersunrefdoesn't exist, so the call is guarded with a typeof check -- no behavior change there.Tested by running the full solid-js test suite (453 tests passing).