Skip to content

Tests that block a pool thread on a pool item's release #758

Closed

Description

@Blind-Striker

testing-style.md now says, by the maintainer's decision:

A test does not block a thread-pool thread on a release that another pool item must perform; it holds the blocking side on a dedicated thread, unless the product itself runs that side on the pool.

The sites below were identified in the original review. This issue closes when each one is fixed or has a recorded reason why it can't be. The list comes from a read of every synchronous wait in tests/OpenCode.Sdk.Tests, checked by a separate reviewer.

Current status: the expiry row still awaits the .NET 11 GA retry with #172. The reason for Preserve_A_Reset is recorded on the row. Cleanup cancellation and invocation now start on dedicated threads, and the readiness test advances time on a dedicated thread. The event-reader late-failure waits now have HangGuard.Bound; the timer-race coverage question remains. Keep this issue together in 1.0.1 rather than split its GA-dependent row from the remaining test work.

Rows still to fix or give a reason for

Paths are under tests/OpenCode.Sdk.Tests. This table preserves the original sites, line numbers and findings; its original state column is historical, not the current checklist. See the status above and the progress comment for subsequent changes.

Site Row or helper What holds, and what releases it State
Terminal/TerminalSocketCoreTests.cs:504 SendAsync_Should_Expire_A_Queued_Call_Without_Closing_The_Socket The OnSent hold runs in a resumed continuation on the pool; a test continuation releases it A form exists, but it crashes CA2025 on rc.3. See below
Terminal/TerminalSocketCoreTests.cs:147 SendAsync_Should_Preserve_A_Reset_Completed_Before_Deadline_Interruption The hold in the AsyncLocal callback runs on the pool; a test continuation releases it No form guarantees it leaves the pool. Inlining the completion on a dedicated thread is best effort only
Harness/Ownership/OwnedCleanupTests.cs:108 CompleteAsync_Should_Bound_An_Operation_And_Its_Stalled_Cancellation_Independently The harness queues the cancellation; a test continuation releases the registration Not tried
Hosting/Launcher/OpenCodeServerReadinessTests.cs:462 Teardown gate A test continuation's release.Set() Not tried. The path through the product wasn't traced
Hosting/Launcher/OpenCodeServerReadinessTests.cs:473 The POSIX counterpart As above Not tried. The path through the product wasn't traced
Support/DiagnosticWriteBarrier.cs:16 Barrier used by harness cleanup rows The harness cleanup worker blocks in capture; the test releases it Not tried
Support/OwnedCleanupDeadlineTests.cs:177 CompleteAsync_Should_Bound_Synchronously_Blocked_Invocation OwnedCleanupOperation.StartAsync queues the invocation; a test continuation releases it Not tried
Support/OwnedEventReaderTests.cs:62 CompleteAsync_Should_Bound_Stalls_Reach_Removal_And_Attach_Late_Failures The harness queues the window's Cancel; the test releases the callback Not tried

Rows the rule's exception covers, to confirm with a reason

The product runs the blocking side on the pool, so the test can't move it. A test continuation releases it, so the hazard is the same. The progress comment records that reasons were subsequently added for all four sites.

Site Why
Hosting/Launcher/OwnedServerChildTests.cs:73 The product's pipe reader invokes the held line callback
Hosting/Launcher/OwnedServerChildTests.cs:358 PipeLineReader starts with the product's Task.Run
Threading/CancellationTokenSourceExtensionsTests.cs:19 CancelOnWorkerAsync runs the callback on the pool. The reason is already in a comment on the row
Terminal/TerminalSocketCoreRentedSendTests.cs:198 The hold on the receive path's buffer return. It keeps the send-ended signal back, which is what forces the refusal through the check behind the gate

The expiry row and CA2025

The form holds inside the physical send and returns a completed task, so the first call stays on a dedicated thread through OnSent. It keeps the row's proof, by reasoning; it has never run. Starting that row's first through DedicatedThread.Run(...).Unwrap() makes the build fail on 11.0.100-rc.3.26522.148:

CSC : error AD0001: Analyzer 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.DoNotPassDisposablesIntoUnawaitedTasksAnalyzer' threw an exception of type 'System.NullReferenceException'

That start alone triggers it. A static local function and a helper-created core crash too. Other rows use the same start without a crash, and the difference hasn't been found. No suppression has been added.

Retry at .NET 11 GA, as part of #172's work. If the crash survives GA, it goes to the maintainer as a possible report to the SDK.

A test gap found on the way

Create_Should_Let_A_Timer_Callback_With_A_Registration_Race_Disposal didn't catch Dispose no longer taking the lock in TimedCancellation's net472 path (lock (_gate) replaced by a check that's always true): 0 kills in 20 runs with the row on Task.Run, and 0 in 20 on dedicated threads. So moving the row didn't cause this. It does catch the callback ignoring _disposed. Decide whether this row, or another one, should catch the lock's removal.

Not in this list

Refs #753. The rows that issue's sampling named as the main holders are moved in the PR that links here. This list is what remains, whether or not it turns out to matter for #753.

Activity

  1. added this to the 1.0 milestone on Nov 2, 2026
  2. Blind-Striker commented on Nov 3, 2026

    @Blind-Striker
    CollaboratorAuthor

    Progress, and two more findings. The PR that links here moves sites 1-5 in the first table, and records the reasons for the four sites in the second. Sites 1-4 move through the harness's own starts, and site 5 through the readiness row's expiry.

    A correction to the first table: the readiness teardown gates (OpenCodeServerReadinessTests.cs:462,473) were on the pool because of the test's own Task.Run(() => time.Advance(...)), not the product.

    Still open here:

    1. TerminalSocketCoreTests.cs:504, the expiry row: retry at .NET 11 GA with Move global.json to the .NET 11 GA SDK #172.
    2. TerminalSocketCoreTests.cs:147, Preserve_A_Reset: the reason is now recorded on the row. No form guarantees the hold leaves the pool.
    3. New: a row that hangs instead of failing. With OwnedCleanup's late-failure observation removed (_lateFailures.Observe(name, pending, ...) given a completed task instead), OwnedEventReaderTests.CompleteAsync_Should_Bound_Stalls_Reach_Removal_And_Attach_Late_Failures never ends. A hang dump after 2 minutes names it as the only test still running. It behaves the same at master, so this PR doesn't cause it. Seven other rows fail at their oracle under the same mutant. That row is missing a bound on that path.
    4. The test gap in the timer race row (above). A reviewer proposes a net472-only row that catches the lock's removal without timing assumptions: hold a registration on a dedicated thread, start Dispose on a second one, and check that the timer wasn't disposed while the callback was held. That check waits on a short bound in each run.
  3. modified the milestones: 1.0, 1.0.1 on Nov 6, 2026
  4. Blind-Striker commented on Nov 10, 2026

    @Blind-Striker
    CollaboratorAuthor

    The expiry row at .NET 11 GA: CA2025 still crashes. I probed it on 2026-11-10, on SDK 11.0.100, at #824's head.

    I made only the recorded trigger: the expiry row's first call starting through DedicatedThread.Run(() => core.SendAsync(...)).Unwrap(). Building OpenCode.Sdk.Tests in Release fails the same way on net11.0, net10.0 and net472:

    CSC : error AD0001: Analyzer 'Microsoft.CodeQuality.Analyzers.QualityGuidelines.DoNotPassDisposablesIntoUnawaitedTasksAnalyzer' threw an exception of type 'System.NullReferenceException' with message 'Object reference not set to an instance of an object.'.
    

    The analyzer comes from a NuGet package, not from the SDK. Directory.Packages.props:7 pins Microsoft.CodeAnalysis.NetAnalyzers at 10.0.402, and Directory.Build.props:84 references it. So the SDK pin doesn't change which analyzer runs, and moving to the GA SDK can't affect this crash. Nothing was committed, and no suppression was added.

    The row moves with this issue to milestone 1.0.2 at the 1.0.1 release cut. Whether to refresh the analyzer package is decided in 1.0.2, as a dependency change of its own.

  5. modified the milestones: 1.0.1, 1.0.2 on Nov 10, 2026
  6. Blind-Striker commented on Nov 14, 2026

    @Blind-Striker
    CollaboratorAuthor

    Finding from the expiry-row work (TerminalSocketCoreTests.SendAsync_Should_Expire_A_Queued_Call_Without_Closing_The_Socket), recorded here because the change for this row does not fix it.

    The row cannot fail at its expiry oracle. It awaits the queued call before it releases the first call's post-send hold. So if a queued call no longer expires, the row waits until the first hold runs out its hang guard, and it then fails at released, not at failure.

    Evidence: the mutant _sendGate.WaitAsync(admission.Token) → _sendGate.WaitAsync(_sendEndedToken) in TerminalSocketCore.SendCoreAsync, run against the row at 0de0be16 and against the changed row:

    row net10.0 net11.0 net472 fails at
    base 30.1 s 30.1 s 30.2 s Assert.That(released).IsTrue()
    changed 30.1 s 30.1 s 30.2 s Assert.That(released).IsTrue()

    The mutant is detected, but by a bounded hold rather than at the row's operation, so by testing-style.md §8 it does not count as killed at the oracle. The row's shape predates this change; the dedicated-thread change neither creates nor fixes it.

  7. Blind-Striker commented on Nov 14, 2026

    @Blind-Striker
    CollaboratorAuthor

    The event-reader row (item 3 of the 11-03 progress comment): it fails now instead of hanging. The mutant is killed at the oracle by other rows, so the row keeps its shape.

    Checked on master e8b3164b (SDK 11.0.100), with the recorded mutant: OwnedCleanup observes a completed task instead of the late operation (_lateFailures.Observe(name, Task.CompletedTask, expectedCancellation)).

    • OwnedEventReaderTests.CompleteAsync_Should_Bound_Stalls_Reach_Removal_And_Attach_Late_Failures passes without the mutant. With it, the row fails at its bounded WaitForFailureAsync(...).WaitAsync(HangGuard.Bound) (OwnedEventReaderTests.cs:94) after 30.1 s on net10.0, net11.0 and net472. It no longer hangs.
    • That is detection by a bound, not a kill at the row's own oracle (testing-style.md §8). Under this mutant every observer completes at once with no failure. So the row's proof can only observe the mutant through a wait: the reader's late failure is observed while the cancellation callback is still held. Reordering the row to wait for all observers first would give an oracle failure, but it would drop that proof.
    • The same mutant is killed at the oracle, in milliseconds, by seven other rows on all three target frameworks. Each fails where it reads the late failures, either an assertion or an empty-sequence read:
      • CompleteAsync_Should_Append_Nested_Late_Failures_To_The_Attached_Queue
      • CompleteAsync_Should_Bound_An_Operation_And_Its_Stalled_Cancellation_Independently
      • CompleteAsync_Should_Bound_Synchronously_Blocked_Invocation
      • CompleteAsync_Should_Observe_Cancellation_After_The_Deadline_Wins_Before_Inspection (both cases)
      • CompleteAsync_Should_Observe_Terminal_Outcome_After_The_Deadline_Wins(True)
      • CleanupAsync_Should_Give_Removal_A_Fresh_Budget_And_Preserve_All_Failures
      • DisposeAsync_Should_Retain_A_Late_Capture_Failure_Without_Delaying_Other_Artifacts

    This item is settled with that reason: the hang is gone, and the mutant has an oracle kill elsewhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions