fix(sea): patch process.dlopen in worker threads - #297
Merged
Conversation
Native addons failed to load from SEA worker threads with ERR_DLOPEN_FAILED on the raw C:\snapshot path. Each worker thread gets its own `process` object, so the `shared.patchDlopen()` call in sea-bootstrap-core only covers the main thread. sea-worker-entry already reapplies `patchIntlSegmenter` for the same reason but was missing `patchDlopen`, so workers never got the extract-to-cache step that makes addons loadable. Classic (non-SEA) pkg is unaffected: bootstrap.js runs in every thread and patches there. test-90-sea-worker-threads now loads a `.node` from the snapshot inside the worker and asserts it was extracted to the native cache. The fake addon is not a real shared library so dlopen throws either way — the extraction is what distinguishes patched from unpatched. Closes #293 Claude-Session: https://claude.ai/code/session_01PUj6PfkgQHcCg2bfXucBzk
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #297 +/- ##
==========================================
+ Coverage 87.19% 87.23% +0.03%
==========================================
Files 23 23
Lines 7929 7929
Branches 1214 1214
==========================================
+ Hits 6914 6917 +3
+ Misses 1008 1005 -3
Partials 7 7 🚀 New features to boost your workflow:
|
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.
Closes #293
Problem
Native addons fail to load from worker threads in SEA mode:
The same code works in classic (non-SEA) pkg.
Cause
patchDlopenis what extracts a.nodeout of the snapshot into~/.cache/pkg/<hash>before handing a real filesystem path to the loader.prelude/sea-bootstrap-core.jscalls it once, on the main thread.Each worker thread gets its own
processobject, so that patch does not carry over:prelude/sea-worker-entry.jsalready reappliessetupProcessPkgandpatchIntlSegmenterper thread for exactly this reason —patchDlopenwas just missing from the list. Workers therefore got the rawC:\snapshot\...path straight through todlopen.Classic pkg is unaffected because
prelude/bootstrap.jsruns in every thread and patches there.Fix
One line in
prelude/sea-worker-entry.js:Same fix the reporter verified in the issue.
Test
Extended
test-90-sea-worker-threadsrather than adding a second SEA build (each postject run costs several seconds in CI). The worker now requires a.nodefrom the snapshot and reports whether it was extracted.The fixture is not a real shared library, so
dlopenthrows in both cases — the discriminator is whether extraction happened, which only occurs whenprocess.dlopenis patched in that thread.index.jspointsPKG_NATIVE_CACHE_PATHat a temp dir so nothing lands in the real~/.cache, andmain.jscleans it up.Verified both directions on linux/node22:
addonExtracted:trueaddonExtracted:false, test failsNote, not fixed here
patchChildProcesshas the same shape —sea-bootstrap-core.jscalls it on the main thread only, andsea-worker-entry.jsdoes not reapply it, while classic pkg patches it in every thread. Nobody has reported it, and it needs its own test, so I left it out of this PR.https://claude.ai/code/session_01PUj6PfkgQHcCg2bfXucBzk