Repository navigation
test(ci): stop FakeOtlpCollectorTests from hanging the integration leg - #1084
Merged
Merged
Conversation
The managed HttpListener drains its accept queue before marking itself closed, so an accept issued during Dispose is never completed. The serve loop now races each accept against the collector's termination, and Dispose bounds its wait for the serve loop.
Owner
Author
|
Review by Codex (gpt-6-astra) at 30a5767 Approve. No P1/P2 or actionable P3 findings.
Validation: Thermo-nuclear review found no structural regression. The change reuses existing terminal state and standard task primitives. Ponytail review: Lean already. Ship. |
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.
Closes #1082
Root cause
The hang is a race inside .NET 10's managed
HttpListener, and the collector waited on it without a bound.FakeOtlpCollector.Dispose()on_serveTask.GetAwaiter().GetResult(). No thread is running listener or socket code, soServeAsyncwas parked on an await that never completed.HttpListener.Managed.cs, release/10.0):Dispose()holds_internalLock, drains_asyncWaitQueueinCleanup, and sets_state = Closedonly in itsfinally.BeginGetContextdoes not take_internalLock. It checks_state == Startedand appends to_asyncWaitQueue. An accept issued between the drain and_state = Closedis therefore never completed.Cleanupcloses the stalled export's connection. That wakes the serve loop through the absorbing catch and back intoGetContextAsync()while the listener still reportsIsListening == true, which is the window above.GetContextAsync(), withIsListening == truewhen the accept was issued.Change map
tests/Cluckwork.Api.IntegrationTests/Infrastructure/FakeOtlpCollector.cs(ServeAsync)_terminal. If termination wins, the loop returns.DisposecallsFaultbefore disposing the listener, so the loop stops whether or not the listener ever completes the accept.Dispose)_serveTask.Wait(10 s), otherwiseTimeoutException("…serve loop did not stop within 10 s of disposal")No product code changed. Test count is unchanged:
FakeOtlpCollectorTestshas 11 tests on base and 11 on head.Evidence
In-process stress probe. A throwaway console app compiles the real
FakeOtlpCollector.csand repeats the hanging test's sequence: stalled export,AssertNoRequestAsync, close the client,Dispose. A hang is aDispose()that has not returned after 5 s. Unpinned, on a 12-core host:origin/main)Pinned to one CPU under three busy loops (the #676 recipe), base gave 0 hangs in 2,000 runs. The race needs two threads running in parallel, so single-CPU pinning hides it.
Real test class loop (
dotnet test --filter FakeOtlpCollectorTests, 60 s blame timeout):Mutation table. Each row was run, then restored.
Disposefails fast with the clear messageTimeoutException: …did not stop within 10 s of disposalin 6,000 runs; 0 hangsIsListeninggate removed so the orphan is reached deterministicallyTimeoutException, failed in 10 sIsListeninggate, base shapeAlso green at head:
OtlpSubprocessExporterTests(11/11), the collector's other caller, andSchemaDocsTests(4/4).Gaps
HttpListenerwith no seam to force it, and a stress test at the measured base rate (about 1 in 600) would not reliably go red. The evidence is the probe and the mutations above.