fix: handle graceful shutdown in safeSend to prevent worker crashes#1109
fix: handle graceful shutdown in safeSend to prevent worker crashes#1109haroldfabla2-hue wants to merge 1 commit intolivekit:mainfrom
Conversation
- Wrap process.send in try-catch to handle channel close errors - Return false instead of throwing when channel is closed (expected during shutdown) - Log at debug level for expected closures, preserving for unexpected errors - Allows job completion flow to continue gracefully Fixes: livekit#1108, livekit#1080
|
|
Alberto Farah seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
|
Do we still need this PR given #1110? Seems they have overlapping changes |
Summary
Fixes issue #1108: IPC safeSend should not throw unhandled errors on channel close during shutdown.
Problem
In
src/ipc/job_proc_lazy_main.ts, thesafeSend()function throws unhandled errors when the message channel closes during normal shutdown sequences. This occurs in production when:safeSend()Solution
Wrap
process.send()in a try-catch block that:falseinstead of throwing when channel is closed (expected during shutdown)This allows the job completion flow in
src/ipc/job_proc_lazy_main.tsto continue gracefully even if the parent has already closed the channel.Changes
safeSend()function inagents/src/ipc/job_proc_lazy_main.tsprocess.send()Testing
The fix allows workers to exit cleanly without throwing when the IPC channel is already closed during shutdown sequence. Related issues: #1080, #1089.