Skip to content

fix: prevent createDeferred from keeping Node.js process alive#2588

Open
veeceey wants to merge 2 commits intosolidjs:mainfrom
veeceey:fix/issue-2570-createdeferred-node-hang
Open

fix: prevent createDeferred from keeping Node.js process alive#2588
veeceey wants to merge 2 commits intosolidjs:mainfrom
veeceey:fix/issue-2570-createdeferred-node-hang

Conversation

@veeceey
Copy link

@veeceey veeceey commented Feb 14, 2026

Fixes #2570

When using createDeferred in Node.js (via node -C browser), the process hangs after all work is done because the internal MessageChannel keeps the event loop alive. The scheduler creates a MessageChannel for task scheduling, and in Node.js, active MessagePort listeners 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 browsers unref doesn'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).

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-bot
Copy link

changeset-bot bot commented Feb 14, 2026

🦋 Changeset detected

Latest commit: 89c39c9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
solid-js Patch
test-integration Patch

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createDeferred hangs the process in nodejs

1 participant

Comments