Repository navigation
Stop reporting a listener that was stopped on purpose as a fault - #1
Merged
Merged
Conversation
OnListeningEnded runs as a continuation of the accept loops and tells a stop from a dead listener by stopRequested. ExecuteSynchronously is only a hint: when the continuation is queued instead, it can run after the stop that ended those loops has finished and the next start has cleared the flag. The stopped generation was then logged at error as "The server stopped listening while it believed it was running", with the stand-in "The accept loop ended while the server was still running." An app that stops and starts the server on resume hits this. Seen in production on iOS (2.2.1): "Shutting down", then "Listening on ...", then that error 5 ms after the new listener was up. The accept loop ends without throwing only when its token was cancelled or stopRequested was set, and only a stop does either, so that stand-in always means a stop. OnListeningEnded now also checks that the loops are still the server's own, the identity rule RecoverFromListenerFaultAsync already applies to the same window.
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the change preventing stale listener callbacks from reporting false faults after a restart.
No open issues 🎉
What changed in this PR
Prevents delayed callbacks from intentionally stopped listeners from logging false faults after the HTTP server restarts.
Changes:
- Checks listener task identity before reporting a fault.
- Adds a regression test and logger factory helper to verify stale callbacks produce no errors and the restarted server remains responsive.
| File | Description |
|---|---|
| tests/Shiny.Net.HttpServer.Tests/ResilienceTests.cs | Tests a stopped listener callback arriving after restart. |
| tests/Shiny.Net.HttpServer.Tests/RecordingLogger.cs | Adds a factory adapter for capturing test logs. |
| src/Shiny.Net.HttpServer/Hosting/HttpServer.cs | Ignores callbacks from obsolete listener tasks. |
Review effort: Balanced
Member
|
Thanks @Kebechet — great catch, and a really clear write-up with the production breadcrumbs. The identity check matches the rule |
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.
Description of Change
OnListeningEndedtells a stop from a dead listener bystopRequested. It runs as a continuation of the accept loops, andExecuteSynchronouslyis only a hint: when the continuation is queued instead of inlined, it can run after the stop that ended those loops has finished and the next start has cleared the flag. The stopped generation is then logged at error as a listener that died underneath a running server.We hit it in production on iOS with 2.2.1 (same code as
mainhere). Our app stops and starts the server when it finds iOS has reclaimed the listening socket of the suspended app. The breadcrumbs, 12 ms apart:That exception is the stand-in for loops that ended without throwing. The accept loop ends that way only when its token (
stopping) was cancelled orstopRequestedwas set, and onlyStopCoreAsyncdoes either, so the stand-in always means a stop. The error came 5 ms after the new listener was up.The fix adds a second check to that guard: the loops must still be the server's own, the same identity rule
RecoverFromListenerFaultAsyncalready applies to this window ("a stop may have completed and a start may have put fresh listeners behind a fresh task"). Recovery was never at risk, because that identity check stopped it; only the false error got out.Issues Resolved
None filed; this PR is the report.
API Changes
None
Behavioral Changes
A stopped listener whose end is observed after the next start is no longer logged as a fault. A listener that dies underneath the running server is reported and recovered exactly as before.
Testing Procedure
ResilienceTests.A_stopped_listener_reported_after_the_next_start_is_not_a_fault: start, stop, start, then handOnListeningEndedthe stopped loops (by reflection, since when a queued continuation runs is the runtime's choice). Before the fix it logs exactly the production error above; after it, nothing at error, and the server keeps serving. Passed 5 runs in a row.ResilienceTests: 12/12 on net10.0, including the existing dead-listener tests.ContentDigestTestscase, a WebDAV name containing<, which Windows paths reject, and two 5 s timing tests).Proposed release note for the documentation repo, under a new
## 3.2.1 TBD(I did not open a PR there):PR Checklist