Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent races between orchestration-invoker and user code #26

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/DurableEngine/SharedMemory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,15 @@ public bool YieldToUserCodeThread(WaitHandle completionHandle)
var shouldStop = index == 0;
return shouldStop;
}

/// <summary>
/// Blocks user code thread if the orchestrator-invoker thread is currently running.
/// This guarantees that the user-code thread and the orchestration-invoker thread run one
/// at a time after this point.
/// </summary>
public void GuaranteeUserCodeTurn()
{
userCodeThreadTurn.WaitOne();
}
}
}
4 changes: 4 additions & 0 deletions src/DurableEngine/Tasks/DurableTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ public DurableTask(SwitchParameter noWait, Hashtable privateData)
/// <param name="writeErr">Function to write an exception to the pipeline.</param>
public void Execute(Action<object> write, Action<ErrorRecord> writeErr)
{
// Ensure that a DurableTask in the usercode thread
// only executes while the orchestration-invoker thread is blocked.
OrchestrationContext.SharedMemory.GuaranteeUserCodeTurn();

DurableTask task = this;

if (NoWait)
Expand Down