fix(relay): never panic delivering to a closed receiver#344
Open
wolfy-j wants to merge 1 commit into
Open
Conversation
The attached process owns its receiver channel and closes it on teardown (Detach only removes the map entry), so a delivery racing that close hit 'send on closed channel' and killed the mailbox worker. Guard the receiver send with recover (a closed receiver = gone process, drop the package) and stop closing the job queues on shutdown (workers exit on ctx.Done) so Send can't race a closed queue either. Test: a closed-receiver send must not stop a live one.
skhaz
approved these changes
Jun 15, 2026
skhaz
approved these changes
Jun 15, 2026
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.
Problem
The relay
Mailboxdelivers to receiver channels it does not own — the attached process owns its channel and closes it on teardown, whileDetach/the Attach cancel only remove the map entry. A delivery racing that close hitpanic: send on closed channelinMailbox.deliverand killed the worker goroutine (process crash under load). The same hazard existed on shutdown:NewMailboxclosed the job queues, so an in-flightSendcould send on a closed queue.Fix
deliverToperforms the receiver-channel send under arecover— a closed receiver means the process is gone, so the package is dropped and the worker survives.ctx.Done()instead of ranging a closed channel, soSendcan't race a closed queue either.Test
TestMailbox_ClosedReceiverDoesNotKillWorkerreproduces the crash: a send to a closed receiver must not stop a subsequent delivery to a live receiver on the same worker. Full packagego test -race+go vetclean.Surfaced in production under heavy process churn (containers starting/dying → mailboxes opening/closing).