Skip to content

Make the finalizer fork safe, and allow for early close#19

Merged
casperisfine merged 1 commit intomasterfrom
fork-safety
Dec 15, 2023
Merged

Make the finalizer fork safe, and allow for early close#19
casperisfine merged 1 commit intomasterfrom
fork-safety

Conversation

@casperisfine
Copy link
Copy Markdown
Contributor

@casperisfine casperisfine commented Dec 15, 2023

Otherwise, when leaning solely on the finalizer, if you fork while an instance is in memory, both the parent and the child will try to wait on it, and will likely lock up.

@casperisfine casperisfine merged commit dd28f8f into master Dec 15, 2023
takaokouji added a commit to speee/schmooze that referenced this pull request Jan 29, 2026
The close() method was calling process_thread.value without first
terminating the Node.js process. If the process doesn't exit when
stdin is closed (e.g., processes with setTimeout or event listeners),
this would hang indefinitely.

This fix adds Process.kill(:KILL, pid) before waiting, consistent
with the finalizer implementation from PR Shopify#19.

Added tests to verify:
- Finalizer does not hang with long-running processes
- Multiple instances are handled correctly under GC pressure
- Fork safety is maintained
- close() method does not hang

Co-Authored-By: Claude Opus 4.5 <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.

2 participants