Skip to content

Fix concurrent timer race condition in InMemoryOrchestrationService#678

Merged
nytian merged 4 commits intomainfrom
nytian/hosttest-timer
Mar 18, 2026
Merged

Fix concurrent timer race condition in InMemoryOrchestrationService#678
nytian merged 4 commits intomainfrom
nytian/hosttest-timer

Conversation

@nytian
Copy link
Contributor

@nytian nytian commented Mar 18, 2026

Fix a thread-safety bug in ReadyToRunQueue where a non-thread-safe Dictionary<string, object> was accessed concurrently from multiple threads, causing orchestrations with identical timer FireAt timestamps to hang indefinitely. Update Dictonary to ConcurrentDictionary for thread-safe operations.

Copilot AI review requested due to automatic review settings March 18, 2026 02:42
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Dictionary with a ConcurrentDictionary for ReadyToRunQueue readiness tracking.
  • Updated removal logic to use TryRemove to match the concurrent collection API.
  • Bumped Microsoft.DurableTask.InProcessTestHost package version to 0.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.

Copilot AI review requested due to automatic review settings March 18, 2026 02:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-safe Dictionary with a ConcurrentDictionary and 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.InProcessTestHost package 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.

@nytian nytian requested a review from cgillum March 18, 2026 04:25
@nytian nytian merged commit e427bbc into main Mar 18, 2026
8 checks passed
@nytian nytian deleted the nytian/hosttest-timer branch March 18, 2026 16:23
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.

3 participants