Skip to content

Fix #4715: Propagate CancellationToken through property injection to prevent hangs#4732

Merged
thomhurst merged 1 commit intomainfrom
fix/4715-property-injection-init-hang
Feb 10, 2026
Merged

Fix #4715: Propagate CancellationToken through property injection to prevent hangs#4732
thomhurst merged 1 commit intomainfrom
fix/4715-property-injection-init-hang

Conversation

@thomhurst
Copy link
Owner

@thomhurst thomhurst commented Feb 10, 2026

Summary

  • Threads the 5-minute discovery timeout CancellationToken from TestDiscoveryService.DiscoverTestsStreamAsync through the entire property injection chain: TestBuilderPipelineTestBuilderObjectLifecycleServicePropertyInjectorEnsureInitializedAsync
  • When IAsyncInitializer.InitializeAsync() hangs during property injection in a chained ClassDataSource dependency pattern, the timeout now fires and unblocks all waiters via OperationCanceledException
  • Adds reproduction test cases covering: immediate failures, slow init (30s delay), discovery-phase failures, attribute-based injection, background process scenarios, and shared object multi-test failures

…t hangs (#4715)

When IAsyncInitializer.InitializeAsync() hangs during property injection
in a chained ClassDataSource dependency pattern, the test runner stalls
indefinitely because CancellationToken.None is passed through the entire
property injection chain. This threads the 5-minute discovery timeout
CancellationToken from TestDiscoveryService through PropertyInjector,
ObjectLifecycleService, TestBuilder, and TestArgumentRegistrationService
so that EnsureInitializedAsync can be cancelled when the timeout fires.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@claude
Copy link
Contributor

claude bot commented Feb 10, 2026

Code review

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


This PR implements a clean solution to the hang issue by threading the cancellation token through the entire property injection chain. The changes are:

  • Mechanically correct: All method signatures are updated consistently, with CancellationToken added as the last optional parameter with default values
  • CLAUDE.md compliant: Works for both source-gen and reflection modes (shared runtime logic), no public API changes, minimal performance impact
  • Well-tested: Comprehensive test coverage including immediate failures, slow initialization, attribute-based injection, and background process scenarios

The architecture properly leverages .NET's cancellation infrastructure to unblock waiting tests when initialization fails or times out, converting an indefinite hang into a graceful failure with OperationCanceledException.

@thomhurst thomhurst merged commit c5f251d into main Feb 10, 2026
12 of 13 checks passed
@thomhurst thomhurst deleted the fix/4715-property-injection-init-hang branch February 10, 2026 21:46
This was referenced Feb 10, 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.

1 participant