Browse Source

Fix SocketAsyncEventArgsAwaitable calling continuation multiple times (#918)

* Fix SocketAsyncEventArgsAwaitable calling continuation multiple times

* Use Interlocked.Exchange

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Igor Milavec 1 year ago
parent
commit
59840ecdba
1 changed files with 2 additions and 3 deletions
  1. 2 3
      src/Renci.SshNet/Abstractions/SocketExtensions.cs

+ 2 - 3
src/Renci.SshNet/Abstractions/SocketExtensions.cs

@@ -33,11 +33,10 @@ namespace Renci.SshNet.Abstractions
                 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();