feat: add SubscribeOpt.Receipt - #148
Open
mkuratczyk wants to merge 2 commits into
Open
Conversation
Conn.Subscribe returns as soon as the SUBSCRIBE frame has been handed to the I/O goroutine, so a message published right afterwards can be lost: the server may not have finished creating the subscription (and any underlying queue/binding) yet. SubscribeOpt.Receipt asks for a RECEIPT on the SUBSCRIBE frame and waits for it before returning, bounded by ConnOpt.SubscribeReceiptTimeout (default 30s, ErrSubscribeReceiptTimeout on expiry). The confirmation is routed via a new writeRequest.ReceiptC rather than writeRequest.C, because for a SUBSCRIBE request C is already the subscription's own frame channel, which the RECEIPT would otherwise consume and close. If the confirmation never arrives, the subscription is unsubscribed again before returning the error. The SUBSCRIBE frame is already on its way to the server at that point and the caller gets no handle back, so otherwise the subscription's readLoop goroutine would leak, and any message the server did deliver for it would eventually fill the unreachable Subscription.C and block processLoop for every other subscription on the connection. Subscribe now also releases closeMutex once the request has been handed over, instead of holding it across the receipt wait, so a slow server does not stall every other operation on the connection. On the (rare) path where the request never reaches processLoop, the frame channel is closed so readLoop does not block on it forever. Reply-to (temporary queue) subscriptions are never sent to the server - processLoop registers the channel locally and drops the frame - so nothing can produce a RECEIPT for them. The receipt header is dropped for those rather than failing every such call after the timeout.
mkuratczyk
force-pushed
the
subscribe-receipt
branch
from
September 3, 2026 08:12
45302c0 to
a8eddcf
Compare
Zerpet
requested changes
Sep 3, 2026
Zerpet
left a comment
Collaborator
There was a problem hiding this comment.
Some feedback. I'm still thinking about Subscribe changes and abandon()
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.
This PR adds an option to request the receipt for the SUBSCRIBE command, so the client can wait until the subscription is confirmed.