Skip to content

feat: Improve graceful shutdown for inline processor, rmq, and sqs#2322

Closed
benjamin-alexander-simplisafe wants to merge 2 commits intoJasperFx:mainfrom
simplisafe-oss:inline-rmq-sqs-graceful-shutdown
Closed

feat: Improve graceful shutdown for inline processor, rmq, and sqs#2322
benjamin-alexander-simplisafe wants to merge 2 commits intoJasperFx:mainfrom
simplisafe-oss:inline-rmq-sqs-graceful-shutdown

Conversation

@benjamin-alexander-simplisafe
Copy link
Copy Markdown
Contributor

@benjamin-alexander-simplisafe benjamin-alexander-simplisafe commented Mar 18, 2026

Hi there. We've recently started using Wolverine for a queue processor that, for various reasons, we need to use with inline mode. This fixes a couple issues we've noticed with it. Admittedly some of the understanding of how this works was Claude assisted so i hope nothing's too off base.

Adds latching and draining for the inline receiver, waiting for already started messages to complete processing and deferring any that haven't. Also added tests for this behavior. This avoids unnecessary re-processing and delays (especially when used with aws sqs).

The following I don't seen any tests covering the existing behavior, so I held off on adding any for now. Let me know if you think it makes sense to add some.

  • Updates listening agent to latch InlineReceivers. Also fixes a bug (i think) where a ReceiverWithRules won't latch the wrapped receiver. If this is unnecessary for some reason I can revert it out.
  • Updates RmqListener to only stop consuming, and not dispose of the consumer, so the channel stays around for acking/nacking/deferring already processing messages while the receiver is draining.
  • Updates SqsListener to cancel the polling loop on StopAsync instead of disposing the entire listener and abandoning in-flight messages. Currently they'll be kicked back to the queue until the visibility timeout expires, which means delayed messages on every deploy.

…spose

Adds latching and draining for the inline receiver, waiting for already
started messages to complete processing and deferring any that haven't.
Fixes a bug in ListeningAgent where a ReceiverWithRules won't latch the
wrapped receiver.
Updates RmqListener to only stop consuming, and not dispose of the consumer, so
the channel stays around for acking/nacking/deferring in-progress messages instead
of forcing redelivery.
Updates SqsListener to cancel the polling loop on StopAsync instead of
immediately disposing the client and abandoning in-flight messages till
the visibility timeout expires.
@benjamin-alexander-simplisafe benjamin-alexander-simplisafe changed the title feat: Gracefuly shutdown for inline processor, rmq, and sqs feat: Improve graceful shutdown for inline processor, rmq, and sqs Mar 18, 2026
Comment on lines +45 to +51
// If _latched was already true, this drain was triggered during shutdown
// (after OnApplicationStopping called Latch()). Safe to wait for in-flight items.
// If _latched was false, this drain may have been triggered from within the handler
// pipeline (e.g., rate limiting pause via PauseListenerContinuation). Waiting for
// in-flight items to complete would deadlock because the current message's
// execute function is still on the call stack.
var waitForCompletion = _latched;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was replicated from the other receivers, and I think is necessary here too.

jeremydmiller added a commit that referenced this pull request Mar 22, 2026
…and SQS

Incorporates changes from benjamin-alexander-simplisafe's PR to improve
graceful shutdown behavior for inline message processing, RabbitMQ, and
Amazon SQS transports.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
jeremydmiller added a commit that referenced this pull request Mar 22, 2026
Upgrade JasperFx + integrate graceful shutdown improvements from PR #2322
@jeremydmiller
Copy link
Copy Markdown
Member

@benjamin-alexander-simplisafe Hey, this got brought in through a different branch, but it'll be in 5.22 shortly. Thank you for contributing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants