Fix InProcessTestHost ContinueAsNew stuck-instance race condition#707
Merged
Fix InProcessTestHost ContinueAsNew stuck-instance race condition#707
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves correctness in the in-process sidecar used by Microsoft.DurableTask.InProcessTestHost, targeting a stuck-instance race condition triggered by ContinueAsNew under concurrency (especially when stale activity/timer messages from a prior execution interleave with a restarted execution).
Changes:
- Adds stress/regression tests that reproduce and validate the
ContinueAsNewstuck-instance scenario under concurrency. - Improves work-item concurrency tracking in the sidecar dispatcher using
InterlockedandVolatile. - Prevents stale message re-enqueue during
ContinueAsNewby clearing accumulated message lists and dropping messages from prior executions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| test/InProcessTestHost.Tests/ContinueAsNewTests.cs | Adds new regression/stress tests targeting the ContinueAsNew stale-message race. |
| src/InProcessTestHost/Sidecar/InMemoryOrchestrationService.cs | Drops messages for completed instances and attempts to drop messages from prior executions after restart. |
| src/InProcessTestHost/Sidecar/Dispatcher/WorkItemDispatcher.cs | Makes active work-item tracking thread-safe via Interlocked/Volatile. |
| src/InProcessTestHost/Sidecar/Dispatcher/TaskOrchestrationDispatcher.cs | Clears accumulated activity/timer/orchestrator message buffers when ContinueAsNew occurs. |
| src/InProcessTestHost/InProcessTestHost.csproj | Bumps package version to 0.2.3-preview.1. |
cgillum
approved these changes
Apr 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
What changed?
This pull request focuses on improving concurrency safety and correctness in the in-process test host, particularly around work item tracking and message handling during orchestration restarts. The most important changes are grouped below.
Concurrency Safety Improvements:
currentWorkItemsfield with thread-safe operations usingInterlocked.Increment,Interlocked.Decrement, andVolatile.ReadinWorkItemDispatcher.cs, ensuring accurate and race-free tracking of concurrent work items.Orchestration Restart and Message Handling Fixes:
TaskOrchestrationDispatcher.cs, added logic to clear accumulated activity, timer, and orchestrator messages when aContinueAsNewoccurs, preventing stale messages from being re-enqueued and causing duplicate or stuck orchestrations.InMemoryOrchestrationService.cs, added logic to drop messages from previous executions after a restart, preventing stale activity completions or timer fires from interfering with new orchestration runs.Version Update:
InProcessTestHost.csprojfrom0.2.2-preview.1to0.2.3-preview.1to reflect these changes.Project checklist
release_notes.mdAI-assisted code disclosure (required)
Was an AI tool used? (select one)
If AI was used:
AI verification (required if AI was used):
Testing
Automated tests
ContinueAsNewRaceConditionTests:ConcurrentContinueAsNew_MultipleIterations_NoneGetStuck— 6 concurrent instances, 5 ContinueAsNew iterations each with activity + 500ms timerSingleInstance_ManyContinueAsNewIterations_CompletesCorrectly— 8 ContinueAsNew iterations with activity + timer per iterationContinueAsNew_MultipleActivitiesPerIteration_AllComplete— 4 concurrent instances with 3 parallel activities per iteration across 4 ContinueAsNew cyclesReproScenario_RepeatedRounds_AllComplete— exact bug report scenario (4 instances, activity + 5s timer + ContinueAsNew) repeated across 3 fresh hosts