From 59840ecdbaad0a0df8a56de71dfb05d3d7896942 Mon Sep 17 00:00:00 2001 From: Igor Milavec Date: Sat, 27 Apr 2024 22:43:42 +0200 Subject: [PATCH] Fix SocketAsyncEventArgsAwaitable calling continuation multiple times (#918) * Fix SocketAsyncEventArgsAwaitable calling continuation multiple times * Use Interlocked.Exchange --------- Co-authored-by: Rob Hague --- src/Renci.SshNet/Abstractions/SocketExtensions.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Renci.SshNet/Abstractions/SocketExtensions.cs b/src/Renci.SshNet/Abstractions/SocketExtensions.cs index b0946c88..eef7c1f6 100644 --- a/src/Renci.SshNet/Abstractions/SocketExtensions.cs +++ b/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();