Skip to content

Fix lost wakeup when NNTP permit wait is cancelled - #206

Merged
enteriaza merged 2 commits into
masterfrom
160-perf-allocation-article-work-parses-every-delivery-with-jsondocument
Oct 19, 2026
Merged

enteriaza merged 2 commits into
masterfrom
160-perf-allocation-article-work-parses-every-delivery-with-jsondocument

Conversation

@enteriaza

@enteriaza enteriaza commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix a concurrency race in NntpSessionPool.AcquirePermitAsync where a cancelled waiter could consume the only available semaphore notification, leaving another waiter blocked indefinitely despite an available permit.

Closes #161

Changes

  • Repost a consumed semaphore notification when another counted permit waiter remains.
  • Keep waiter-count cleanup and notification recovery in a finally block so test-hook exceptions cannot leave waiter accounting elevated.
  • Add test-only coordination hooks to reproduce the cancellation race deterministically.
  • Add Cancelled_permit_wait_does_not_consume_the_only_wakeup, exercising the race across eight coordinated cycles and verifying that:
    • The cancelled waiter does not acquire or reserve a permit.
    • The surviving waiter acquires the released permit without requiring a second release.
    • A subsequent waiter remains blocked until the acquired lease is returned.
    • Permit availability and reservation accounting remain consistent.

Validation

  • Focused NntpSessionPool tests: 52 passed
  • Related Article Work lifecycle and provider registry tests: 19 passed
  • Full BackFillerService test suite: 1,260 passed, 0 failed, 0 skipped
  • Release x64 solution build: 0 warnings, 0 errors
  • Solution format verification: passed

Outstanding checks

  • CodeQL: not run
  • Linux CI: not run

Fixes #161

Repost a consumed semaphore notification when another permit waiter
remains, preventing an available permit from being stranded after
cancellation. Add a deterministic regression test for the race.
@enteriaza enteriaza self-assigned this Oct 19, 2026
@enteriaza enteriaza added the bug Something isn't working label Oct 19, 2026
Scope each cycle's CancellationTokenSource with using so it is
disposed on exceptional exits while preserving gate-release
ordering and deterministic regression-test cleanup.
@enteriaza
enteriaza merged commit e1fcf87 into master Oct 19, 2026
7 checks passed
@enteriaza
enteriaza deleted the 160-perf-allocation-article-work-parses-every-delivery-with-jsondocument branch October 19, 2026 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug: Concurrency] Cancelled NNTP pool permit wait can consume the only wakeup

2 participants