From b3e5b208b43e490149ce78d4421078b49b42dfde Mon Sep 17 00:00:00 2001 From: Jose Date: Wed, 6 Nov 2024 16:08:51 +0100 Subject: [PATCH] Fix C# connection to correctly mark message as sent (#3072) --- csharp/src/Ice/ConnectionI.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/csharp/src/Ice/ConnectionI.cs b/csharp/src/Ice/ConnectionI.cs index 13c0172bdcf..bdb68e101da 100644 --- a/csharp/src/Ice/ConnectionI.cs +++ b/csharp/src/Ice/ConnectionI.cs @@ -607,15 +607,23 @@ public override bool startAsync(int operation, Ice.Internal.AsyncCallback comple observerStartWrite(_writeStream.getBuffer()); } - bool completed; - if (_transceiver.startWrite(_writeStream.getBuffer(), completedCallback, this, out completed)) + bool messageWritten = false; + bool completedSynchronously = + _transceiver.startWrite( + _writeStream.getBuffer(), + completedCallback, + this, + out messageWritten); + // If the startWrite call consumed the complete buffer, we assume the message is sent now for + // at-most-once semantics. + if (messageWritten && _sendStreams.Count > 0) { - // If the write completed immediately and the buffer - if (completed && _sendStreams.Count > 0) - { - // The whole message is written, assume it's sent now for at-most-once semantics. - _sendStreams.First.Value.isSent = true; - } + _sendStreams.First.Value.isSent = true; + } + + if (completedSynchronously) + { + // If the write completed synchronously, we need to call the completedCallback. completedCallback(this); } }