Commit 5402f85
fix(jobs): unref parentPort after job completes to prevent Bun NAPI crash
The prior commit's premise was wrong. The actual root cause is a Bun 1.3.13
bug: calling process.exit() in a worker_threads.Worker that has lmdb-js
loaded, while sibling workers are running, triggers a NAPI fatal error
(panic: NAPI FATAL ERROR: Error::New napi_create_error) crashing the whole
process.
The crash chain for the CSV upsert integration test:
1. northnwd.suppliers has schemaDefined=false (create_table without attributes)
2. CSV upsert with a new column triggers addAttributes → signalSchemaChange
→ broadcastWithAcknowledgement, which calls port.ref() on ALL ports
including parentPort
3. After ACKs received, parentPort is never unref'd (by design for regular
workers, but wrong for job workers)
4. parentPort ref keeps the event loop alive until the 3s unref'd timer fires
5. realExit() → process.exit() in the lmdb-bearing job worker → Bun crash
Fix: unref parentPort after updateJob so the event loop drains naturally,
avoiding process.exit() entirely. Remove the setInterval keepalive which
was based on the incorrect premise.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>1 parent f9f36ca commit 5402f85
1 file changed
Lines changed: 6 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | 30 | | |
36 | 31 | | |
37 | 32 | | |
| |||
83 | 78 | | |
84 | 79 | | |
85 | 80 | | |
86 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
87 | 86 | | |
88 | 87 | | |
89 | 88 | | |
| |||
0 commit comments