Skip to content

Stop SyntheticPeer teardown from failing skipped tests - #45

Merged
ligenq merged 1 commit into
mainfrom
fix-synthetic-peer-teardown-race
Nov 22, 2026
Merged

ligenq merged 1 commit into
mainfrom
fix-synthetic-peer-teardown-race

Conversation

@ligenq

@ligenq ligenq commented Nov 22, 2026

Copy link
Copy Markdown
Owner

Fixes the failure in the latest 5.4.1 release run (Ubuntu interop) and brings the docs up to date with #44.

The failure

LibtorrentAlsoDialsAPeerIntroducedOnlyBySyntheticPex failed in 41 ms with InvalidOperationException: Not listening, when it should have been skipped (PEERSHARP_INTEROP isn't set in that job).

The test starts two SyntheticPeers and then skips. await using disposes them a few milliseconds later. SyntheticPeer's accept loop checks _stopping, then calls AcceptTcpClientAsync. If DisposeAsync cancels and stops the listener between those two steps, TcpListener throws "Not listening" before it looks at the token, and the loop's catch filter didn't cover that. DisposeAsync then rethrew it, and an exception from await using replaces the test's own outcome, so the skip became a failure.

Changes

  • SyntheticPeer: the accept loop treats InvalidOperationException as shutdown when _stopping is already cancelled. DisposeAsync cancels _stopping before stopping the listener, so that ordering always holds during shutdown. The same exception at any other time still surfaces.
  • tests/README.md: notes that Leeching_FromTransmission_ReceivesTheWholeFile skips on Windows unless PEERSHARP_TRANSMISSION_LEECH_ON_WINDOWS=1, and why. This was missing from Skip leeching from Transmission on Windows in the release gate #44.
  • CHANGELOG.md (5.4.1, Testing): says that downloading from Transmission is checked on Linux only. The library itself is unchanged, so the package notes and the main README stay as they are.

Validation

  • dotnet format --verify-no-changes is clean, and the Release build with warnings as errors succeeds.
  • All 40 tests that use SyntheticPeer pass, and the libtorrent oracle tests skip cleanly.
  • The dry run before Skip leeching from Transmission on Windows in the release gate #44 confirmed that Ubuntu interop runs and passes both Transmission tests, so the Linux claims in the docs hold.
  • No regression test. A start-and-dispose stress test (64 peers × 20 rounds) did not hit the race on the unfixed code, because the window is a single step: the loop has to pass its check just before dispose stops the listener. A deterministic test would need a hook inside the loop, which seemed like more than this fix warrants.

After merging

5.4.1 is still unpublished. Run the Release workflow on main again rather than re-running the old run's failed job, so the tagged commit includes these docs.

🤖 Generated with Claude Code

…Windows Transmission skip

SyntheticPeer's accept loop checks _stopping, then calls AcceptTcpClientAsync.
If DisposeAsync cancels and stops the listener between the two, TcpListener
throws InvalidOperationException ("Not listening") before it looks at the
token, and the catch filter did not cover it. DisposeAsync then rethrew it,
and from an `await using` that replaces the test's own outcome: a libtorrent
oracle test that skips straight after starting two peers was reported as
failed, and failed the 5.4.1 release run on Ubuntu. The loop now treats that
exception as shutdown when _stopping is already cancelled, which DisposeAsync
does before it stops the listener.

No regression test: start-and-dispose stress over 1,280 peers did not hit the
window, which needs the loop to pass its check and dispose to run before the
very next call. A deterministic test would need a hook inside the loop.

Also brings the docs up to date with the release gate change in #44:
tests/README.md says that leeching from Transmission skips on Windows and how
to opt back in, and the 5.4.1 changelog says that downloading from
Transmission is checked on Linux only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ligenq
ligenq merged commit 86eaa8c into main Nov 22, 2026
17 checks passed
@ligenq
ligenq deleted the fix-synthetic-peer-teardown-race branch November 22, 2026 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant