Skip to content

Commit ce156e6

Browse files
authored
Fix issue #584 - Update TaskExtensions.cs (#585)
Execute link.Send() in a try-catch block. If an error occurs, no action is needed because the client already received an exception.
1 parent eea885a commit ce156e6

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/Net/TaskExtensions.cs

+17-2
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,31 @@ class SendTask : TaskCompletionSource<bool>
279279
readonly static OutcomeCallback onOutcome = OnOutcome;
280280
readonly static TimerCallback onTimer = OnTimer;
281281
readonly Timer timer;
282+
readonly bool isFaulted;
282283

283284
public SendTask(SenderLink link, Message message, DeliveryState state, TimeSpan timeout)
284285
{
285286
this.timer = new Timer(onTimer, this, (int)timeout.TotalMilliseconds, -1);
286-
link.Send(message, state, onOutcome, this);
287+
try
288+
{
289+
link.Send(message, state, onOutcome, this);
290+
}
291+
catch (Exception)
292+
{
293+
this.isFaulted = true;
294+
this.timer.Dispose();
295+
throw;
296+
}
287297
}
288298

289299
static void OnOutcome(ILink link, Message message, Outcome outcome, object state)
290300
{
291301
SendTask thisPtr = (SendTask)state;
302+
if (thisPtr.isFaulted)
303+
{
304+
return;
305+
}
306+
292307
thisPtr.timer.Dispose();
293308

294309
if (outcome.Descriptor.Code == Codec.Accepted.Code)
@@ -481,4 +496,4 @@ await pump.PumpAsync(
481496
return (IAsyncTransport)saslProfile.UpgradeTransportInternal(transport);
482497
}
483498
}
484-
}
499+
}

0 commit comments

Comments
 (0)