Skip to content

Commit

Permalink
Fix SocketAsyncEventArgsAwaitable calling continuation multiple times (
Browse files Browse the repository at this point in the history
…#918)

* Fix SocketAsyncEventArgsAwaitable calling continuation multiple times

* Use Interlocked.Exchange

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
  • Loading branch information
IgorMilavec and Rob-Hague authored Apr 27, 2024
1 parent 4e1e243 commit 59840ec
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/Renci.SshNet/Abstractions/SocketExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ public AwaitableSocketAsyncEventArgs ExecuteAsync(Func<SocketAsyncEventArgs, boo
return this;
}

public void SetCompleted()
private void SetCompleted()
{
IsCompleted = true;

var continuation = _continuationAction ?? Interlocked.CompareExchange(ref _continuationAction, SENTINEL, comparand: null);
var continuation = Interlocked.Exchange(ref _continuationAction, SENTINEL);
if (continuation is not null)
{
continuation();
Expand Down

0 comments on commit 59840ec

Please sign in to comment.