Skip to content

Latch receiver after stopping listener on shutdown#2391

Merged
jeremydmiller merged 2 commits intoJasperFx:mainfrom
simplisafe-oss:latch-receiver-after-stopping-listener-on-shutdown
Mar 31, 2026
Merged

Latch receiver after stopping listener on shutdown#2391
jeremydmiller merged 2 commits intoJasperFx:mainfrom
simplisafe-oss:latch-receiver-after-stopping-listener-on-shutdown

Conversation

@benjamin-alexander-simplisafe
Copy link
Copy Markdown
Contributor

Currently, wolverine latches all receivers immediately when shutdown is requested. This means that any messages consumed by listeners after that happens are deferred, which (for the same reasons as in #2347) can have poor performance characteristics.

This change moves latching each receiver to after its respective listener is stopped, so all consumed messages get a fair shot at being processed.

This also moves to shutting down the listeners in parallel so that they don't wait to latch before the previous ones finish shutting down. This was also done to the ParallelListener, with similar exception aggregation to the CompoundListener. I think this is a general improvement to the shutdown flow, but also avoids extra bad behavior from moving latching.

This avoids deferring messages during shutdown, which current happens
when the listener receives messages after the receiver is latched.
This should speed up the shutdown process in general (and,
importantly, means that the previous commit won't stall shutdown
by waiting to latch listener B until listener A is stopped and drained.
Technically this was a risk before, but since deferring messages is a
fast operation it wasn't as important). This should be safe, since each
StopAsync is wrapped in a try-catch. Also updated the ParallelListener
to stop children in parallel, which avoids one error from preventing
other attempts (similar to the CompoundListener) and should further
speed things up.
@jeremydmiller
Copy link
Copy Markdown
Member

@benjamin-alexander-simplisafe Hey, I'm going to try to get this in for the next release, but as I'm sure you completely understand, I need to review this one carefully!

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