feat(message): add Stoppable interface for graceful subscriber shutdown#678
Draft
SinuheTellez wants to merge 1 commit intoThreeDotsLabs:masterfrom
Draft
feat(message): add Stoppable interface for graceful subscriber shutdown#678SinuheTellez wants to merge 1 commit intoThreeDotsLabs:masterfrom
SinuheTellez wants to merge 1 commit intoThreeDotsLabs:masterfrom
Conversation
Relates to ThreeDotsLabs#446 During graceful shutdown, the router now checks if a subscriber implements the Stoppable interface. If so, it calls Stop() first to halt new message delivery, waits for in-flight handlers to finish, then calls Close(). This prevents double-handling caused by in-flight messages losing their chance to be acked or nacked when the subscriber is closed immediately.
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.
Background/Description
During graceful shutdown the router calls
subscriber.Close()immediately, which cancels in-flight message processing — messages that were mid-handler lose their chance to be acked or nacked. When the subscriber re-connects, those messages get redelivered and double-handled.This adds a
Stoppableinterface (Stop() error) that subscribers can optionally implement.Stop()tells the subscriber to stop delivering new messages while keeping the connection alive so in-flight messages can still be acked or nacked.The router's
handleClosenow checks if the subscriber implementsStoppable. If it does: callStop(), wait for running handlers to finish (runningHandlersWg.Wait()), then callClose(). Non-stoppable subscribers behave exactly as before.The
originalSubscriberfield was added to the handler struct becausedecorateHandlerSubscriberwraps the subscriber withMessageTransformSubscriberDecorator, which doesn't implementStoppable. The type assertion checks the unwrapped subscriber.Relates to #446
Type of Change