Skip to content

Commit

Permalink
Cancel and signal to ensure the async processor ends
Browse files Browse the repository at this point in the history
  • Loading branch information
badrishc committed May 29, 2024
1 parent 59b4ab9 commit 39be321
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions libs/server/Resp/AsyncProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ internal sealed partial class RespServerSession : ServerSessionBase
/// </summary>
SingleWaiterAutoResetEvent asyncWaiter = null;

/// <summary>
/// Cancellation token source for async waiter
/// </summary>
CancellationTokenSource asyncWaiterCancel = null;

/// <summary>
/// Semaphore for barrier command to wait for async operations to complete
/// </summary>
Expand All @@ -51,6 +56,7 @@ void NetworkGETPending<TGarnetApi>(ref TGarnetApi storageApi)

if (++asyncStarted == 1) // first async operation on the session, create the IO continuation processor
{
asyncWaiterCancel = new();
asyncWaiter = new()
{
RunContinuationsAsynchronously = true
Expand Down Expand Up @@ -131,6 +137,9 @@ async Task AsyncGetProcessor<TGarnetApi>(TGarnetApi storageApi)
// Wait for next async operation
// We do not need to cancel the wait - it should get garbage collected when the session ends
await asyncWaiter.WaitAsync();

if (asyncWaiterCancel.Token.IsCancellationRequested)
break;
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions libs/server/Resp/RespServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ public override void Dispose()

subscribeBroker?.RemoveSubscription(this);

// Cancel the async processor, if any
asyncWaiterCancel?.Cancel();
asyncWaiter?.Signal();

storageSession.Dispose();
}

Expand Down

0 comments on commit 39be321

Please sign in to comment.