Repository navigation
Refuse to schedule a reconnect while an attempt is in flight - #23
Merged
Merged
Conversation
The health check reads the registration state without the lock. When it read TemporaryFailure just before a scheduled attempt started, its ScheduleReconnection() call ran with that attempt already in flight and scheduled another one: an attempt no failure asked for, and in extended mode the in-flight agent was stopped before it could report its result. CI on master caught it as more reconnect attempts than failures. ScheduleReconnection() now also refuses while RegistrationState is Registering, checked under the lock. New deterministic test: calling it during an in-flight attempt starts nothing and the attempt still reports its failure (without the fix: 1 attempt, expected 0). The registration timing tests also failed on a starved runner (reproduced by pinning the tests to one CPU): SIPSorcery blocks thread-pool threads during each attempt, and with test classes running in parallel the pool grew by about one thread a second, so timers fired ~1 s late. The test assembly now raises the thread-pool minimum when it loads. Closes #22 Co-Authored-By: Claude Opus 5.5 <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.
Summary
Closes #22. This is a follow-up to #19.
CI on
mastere7bedeefailedRegistrationHealthCheckInFlightTestswith more reconnect attempts than failures (4 for 3, and 4 for 2).PerformHealthCheckreads_registrationStatewithout the lock. If it readTemporaryFailurejust before a scheduled attempt started, itsScheduleReconnection()call ran with that attempt already in flight and scheduled another one. That attempt had no failure behind it, and in extended mode the in-flight agent was stopped before it could report its own result. #19 closed this at the health-check level; the remaining window was between the unlocked read and the lock.Changes
SipClient.ScheduleReconnection()also refuses whileRegistrationStateisRegistering, checked under the lock. It is nowinternalso the race can be tested directly.TestSetup: the test assembly raises the thread-pool minimum when it loads. SIPSorcery blocks thread-pool threads during each registration attempt, and with test classes running in parallel on a small runner, the pool grew by about one thread a second. Timers then fired ~1 s late, and the registration timing tests failed. This was reproduced by pinning the tests to one CPU withtaskset. Test setup only; library behavior is unchanged.Tests
RegistrationScheduleRaceTests(deterministic): callingScheduleReconnection()while an attempt is in flight starts nothing, and the attempt still reports its own failure, in both modes. Without the fix, both cases fail withExpected 0, Actual 1.dotnet test: 97 passed.taskset -c 0): with the thread-pool minimum, 5 of 5 runs passed (97/97 each). Without it, 4 of 7 runs had a timing failure (a gap of ~1 s where 100–800 ms was expected).🤖 Generated with Claude Code