Skip to content

CancelAll racing Dispose can throw ObjectDisposedException from the disposed CTS #368

Description

@thomhurst

Found in the pre-4.0 audit (follow-up to #360/#361).

ProcessorLifecycle.CancelAll checks _disposed without the dispose lock, then CancelAllCore calls _cancellationTokenSource.Cancel(). A concurrent Dispose() can pass its own flag check and dispose the CTS inside that window, so the external CancelAll() caller gets ObjectDisposedException.

The README promises "all disposal operations are thread-safe", and ResultAsyncEnumerableParallelProcessor.CancelForDisposal already handles this exact race by catching ObjectDisposedException — the lifecycle should match.

Fix: catch ObjectDisposedException around the Cancel() call in CancelAllCore (still complete the per-item completion sources as canceled), mirroring the streaming processor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions