Skip to content

Commit

Permalink
Fix issue Azure#584 - Update TaskExtensions.cs
Browse files Browse the repository at this point in the history
Execute link.Send() in a try-catch block. If an error occurs, no action is needed because the client already received an exception.
  • Loading branch information
RusuIonut21 authored Jun 6, 2024
1 parent eea885a commit af39a0b
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/Net/TaskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,16 +279,31 @@ class SendTask : TaskCompletionSource<bool>
readonly static OutcomeCallback onOutcome = OnOutcome;
readonly static TimerCallback onTimer = OnTimer;
readonly Timer timer;
readonly bool isFaulted;

public SendTask(SenderLink link, Message message, DeliveryState state, TimeSpan timeout)
{
this.timer = new Timer(onTimer, this, (int)timeout.TotalMilliseconds, -1);
link.Send(message, state, onOutcome, this);
try
{
link.Send(message, state, onOutcome, this);
}
catch (Exception)
{
this.isFaulted = true;
this.timer.Dispose();
throw;
}
}

static void OnOutcome(ILink link, Message message, Outcome outcome, object state)
{
SendTask thisPtr = (SendTask)state;
if (thisPtr.isFaulted)
{
return;
}

thisPtr.timer.Dispose();

if (outcome.Descriptor.Code == Codec.Accepted.Code)
Expand Down Expand Up @@ -481,4 +496,4 @@ await pump.PumpAsync(
return (IAsyncTransport)saslProfile.UpgradeTransportInternal(transport);
}
}
}
}

0 comments on commit af39a0b

Please sign in to comment.