Fix concurrent timer race condition in InMemoryOrchestrationService#678
Fix concurrent timer race condition in InMemoryOrchestrationService#678
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency bug in the in-memory test host’s orchestration scheduling path by making the “ready-to-run” deduplication tracking thread-safe, preventing potential hangs when multiple orchestrations are scheduled concurrently (e.g., timers firing at the same time).
Changes:
- Replaced a non-thread-safe
Dictionarywith aConcurrentDictionaryforReadyToRunQueuereadiness tracking. - Updated removal logic to use
TryRemoveto match the concurrent collection API. - Bumped
Microsoft.DurableTask.InProcessTestHostpackage version to0.2.1-preview.1.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/InProcessTestHost/Sidecar/InMemoryOrchestrationService.cs | Makes ready-instance tracking thread-safe to prevent concurrency-related hangs in scheduling. |
| src/InProcessTestHost/InProcessTestHost.csproj | Increments package version to reflect the bug fix. |
There was a problem hiding this comment.
Pull request overview
Fixes a concurrency issue in the in-memory test host orchestration scheduler where non-thread-safe tracking of “ready” instances could cause orchestrations with identical timer FireAt timestamps to hang, and adds regression tests to validate correct completion under timer contention.
Changes:
- Replace
ReadyToRunQueue’s non-thread-safeDictionarywith aConcurrentDictionaryand update removal logic accordingly. - Add new tests that schedule multiple orchestrations/sub-orchestrations with identical timer fire times and assert they all complete.
- Bump the
Microsoft.DurableTask.InProcessTestHostpackage version.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| test/InProcessTestHost.Tests/ConcurrentTimerTests.cs | Adds regression tests for concurrent timers with identical FireAt timestamps. |
| src/InProcessTestHost/Sidecar/InMemoryOrchestrationService.cs | Makes ReadyToRunQueue’s instance tracking thread-safe using ConcurrentDictionary. |
| src/InProcessTestHost/InProcessTestHost.csproj | Updates package version to include the fix. |
Fix a thread-safety bug in
ReadyToRunQueuewhere a non-thread-safeDictionary<string, object>was accessed concurrently from multiple threads, causing orchestrations with identical timer FireAt timestamps to hang indefinitely. UpdateDictonarytoConcurrentDictionaryfor thread-safe operations.