GO-7116 Fix deadlock on app close in inboxclient#3057
Merged
requilence merged 4 commits intodevelopfrom Apr 15, 2026
Merged
Conversation
Add componentCtx to inboxclient that gets cancelled on Close(), and propagate context through fetchMessages/getOffset/setOffset instead of using context.Background(). Previously, periodicCheck.Close() would wait for the periodic loop to finish, but the loop's callback used context.Background() for RPC calls (InboxFetch), making them uncancellable. When the coordinator connection went stale, the RPC would block forever, causing a deadlock on shutdown.
deff7
reviewed
Mar 27, 2026
Coverage provided by https://github.com/seriousben/go-patch-cover-action |
deff7
approved these changes
Apr 14, 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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Summary
componentCtxto inboxclient that gets cancelled onClose(), ensuring all operations (both periodic and external callback) are cancellable on shutdownfetchMessages/getOffset/setOffsetinstead of hardcodedcontext.Background()Problem
inboxclient.Close()deadlocks when the coordinator connection is stale. The periodic sync callback (checkMessages) ignores its context parameter and callsfetchMessages()which usescontext.Background()for theInboxFetchRPC. When the coordinator doesn't respond, the RPC blocks forever, andperiodicCall.Close()waits indefinitely for the loop to finish.Deadlock chain:
app.Close()→inboxclient.Close()→periodicCheck.Close()→ cancels loop context, waits on<-loopDonecheckMessages(ctx)→ ignores ctx →fetchMessages()→InboxFetch(context.Background())→ blocked forever on stale DRPC streamTest plan
ReceiveNotify(external callback) now usescomponentCtxinstead ofcontext.Background()— also cancellable on close