Skip to content

Comments

fix: propagate CancellationToken to inner loop in AotConverterGenerator#4916

Merged
thomhurst merged 1 commit intomainfrom
fix/cancellation-propagation
Feb 19, 2026
Merged

fix: propagate CancellationToken to inner loop in AotConverterGenerator#4916
thomhurst merged 1 commit intomainfrom
fix/cancellation-propagation

Conversation

@thomhurst
Copy link
Owner

Summary

  • Adds cancellationToken.ThrowIfCancellationRequested() at the start of the DescendantNodes() inner loop in ScanTestParameters, ensuring the generator responds to cancellation during long-running node traversals
  • The outer syntax tree loop and the typesToScan loop already had cancellation checks, but the potentially large inner loop over all descendant nodes in each tree did not

Test plan

  • dotnet build TUnit.Core.SourceGenerator/TUnit.Core.SourceGenerator.csproj succeeds with zero warnings and zero errors
  • Existing source generator snapshot tests pass (no output change expected since this is a behavioral fix only)

Closes #4900

…ConverterGenerator

The ScanTestParameters method accepted a CancellationToken but only
checked it at the start of the outer syntax tree loop. The inner loop
over DescendantNodes — which can iterate over a very large number of
nodes per syntax tree — did not check for cancellation, causing the
generator to remain unresponsive to cancellation requests during
long-running node traversals.

Closes #4900
@claude
Copy link
Contributor

claude bot commented Feb 19, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

This is a clean, well-targeted fix. Adding cancellationToken.ThrowIfCancellationRequested() at the top of the DescendantNodes() inner loop is the correct and idiomatic Roslyn pattern for cooperative cancellation. The placement is right (before any work is done each iteration), the API is correct (ThrowIfCancellationRequested() is zero-allocation — just a volatile read and branch), and the fix is minimal with no behavioral side effects on generated output.

The dual-mode rule does not apply here since AotConverterGenerator is a compile-time-only concern with no reflection-mode equivalent.

@thomhurst thomhurst merged commit 065bbca into main Feb 19, 2026
14 checks passed
@thomhurst thomhurst deleted the fix/cancellation-propagation branch February 19, 2026 01:10
This was referenced Feb 22, 2026
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.

fix: cancellation token not propagated in AotConverterGenerator inner loops

1 participant