#499: terminate coordinator loop on disposed data source / wrapped cancellation#500
Merged
Merged
Conversation
…urce / wrapped cancellation ProjectionCoordinatorBase.executeAsync's per-set error handler treated any exception from TryAttainLockAsync as a transient "will retry later" and looped again after Task.Delay. During host shutdown that turned one racing OpenAsync against a disposing NpgsqlDataSource into the burst of ObjectDisposedException aborts measured in marten#4874 (case B — the root-cause drain correctness fix). The inner catch now: - returns out of the loop on ObjectDisposedException (the data source is gone for good; re-polling only hammers a dead pool), and - checks stoppingToken.IsCancellationRequested before the retry Delay, so a cancellation that surfaces wrapped (not a bare OperationCanceledException) terminates the loop the same way the outer catch already does. Adds two regression tests that fail against the pre-fix loop: one proves a disposed-pool fault stops the loop without re-polling, the other proves a wrapped shutdown cancellation terminates without logging a lock error. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #499.
Problem
ProjectionCoordinatorBase.executeAsync's per-set error handler treated any exception fromTryAttainLockAsyncas a transient "will retry later" and looped again afterTask.Delay. During host shutdown, aTryAttainLockAsyncthat faults because the underlyingNpgsqlDataSourceis being disposed got re-polled instead of terminating — amplifying one racingOpenAsyncinto the burst ofObjectDisposedException: 'Npgsql.PoolingDataSource'aborts measured in marten#4874. This is priority 2 (case B) of that issue — the root-cause drain correctness fix (the priority-1 symptom guard lives in weasel#349).Change
In the inner lock-attempt catch of
ProjectionCoordinatorBase.executeAsync:ObjectDisposedExceptionis now terminal — the data source is gone for good, so the loopreturns instead of re-polling a dead pool.stoppingToken.IsCancellationRequestedbefore the retryTask.Delay— a cancellation that surfaces wrapped (not a bareOperationCanceledException) now terminates the loop the same way the outer catch already does, rather than being logged as a lock error and re-polled.Tests
Two regression tests in
ProjectionCoordinatorBaseTests, both confirmed to fail against the pre-fix loop:terminates_the_loop_when_the_data_source_is_disposed_mid_lock_attempt— a disposed-pool fault stops the loop after exactly one attempt (a re-polling loop would keep incrementing the attempt counter).terminates_on_a_wrapped_cancellation_during_a_lock_attempt_without_logging_a_lock_error— an in-flight attempt whose cancellation surfaces wrapped terminates without logging a "will retry later" lock error (asserted via a capturing logger).All 13 coordinator tests pass with the fix.
🤖 Generated with Claude Code