Skip to content

Commit

Permalink
fix a rare race condition in treeaction timeout detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Zheng Mu committed Jan 22, 2021
1 parent 3764a54 commit 3173bfb
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions Forge.TreeWalker/src/TreeWalkerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -801,19 +801,6 @@ internal async Task PerformActionTypeBehavior(TreeNode treeNode, string treeNode
// Break out early if we would hit timeout before next retry.
if (actionTimeout != -1 && stopwatch.ElapsedMilliseconds + waitTime.TotalMilliseconds >= actionTimeout)
{
// If the timeout is hit and the ContinuationOnTimeout flag is set, commit a new ActionResponse.
// with the status set to TimeoutOnAction and return.
if (treeAction.ContinuationOnTimeout)
{
ActionResponse timeoutResponse = new ActionResponse
{
Status = "TimeoutOnAction"
};

await this.CommitActionResponse(treeActionKey, timeoutResponse).ConfigureAwait(false);
return;
}

break;
}

Expand All @@ -823,6 +810,22 @@ internal async Task PerformActionTypeBehavior(TreeNode treeNode, string treeNode
maxRetryCount--;
}

if (actionTimeout != -1 && stopwatch.ElapsedMilliseconds + waitTime.TotalMilliseconds >= actionTimeout)
{
// If the timeout is hit and the ContinuationOnTimeout flag is set, commit a new ActionResponse.
// with the status set to TimeoutOnAction and return.
if (treeAction.ContinuationOnTimeout)
{
ActionResponse timeoutResponse = new ActionResponse
{
Status = "TimeoutOnAction"
};

await this.CommitActionResponse(treeActionKey, timeoutResponse).ConfigureAwait(false);
return;
}
}

// Retries are exhausted. Throw ActionTimeoutException with executeAction exception as innerException.
throw new ActionTimeoutException(
string.Format(
Expand Down

0 comments on commit 3173bfb

Please sign in to comment.