Skip to content

Commit

Permalink
Add a bufferred timeout in transport initiator.
Browse files Browse the repository at this point in the history
  • Loading branch information
xinchen10 committed Apr 10, 2023
1 parent 83dcc6d commit 8cc962e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Microsoft.Azure.Amqp/Amqp/Transport/AmqpTransportInitiator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,14 @@ void Complete(TransportAsyncCallbackArgs args)

sealed class ConnectAsyncResult : TimeoutAsyncResult<string>
{
// Inner initiator may also have a timer, so don't compete with them.
const int BufferedTimeInTicks = 5000 * 10000;
static Action<TransportAsyncCallbackArgs> onConnect = OnConnect;
readonly AmqpTransportInitiator initiator;
readonly TransportAsyncCallbackArgs args;

public ConnectAsyncResult(AmqpTransportInitiator initiator, TimeSpan timeout, CancellationToken cancellationToken, AsyncCallback callback, object state)
: base(timeout, cancellationToken, callback, state)
: base(GetBufferedTimeout(timeout), cancellationToken, callback, state)
{
this.initiator = initiator;
this.args = new TransportAsyncCallbackArgs();
Expand Down Expand Up @@ -302,6 +304,16 @@ protected override void CompleteOnTimer()
base.CompleteOnTimer();
}

static TimeSpan GetBufferedTimeout(TimeSpan timeout)
{
if (timeout.Ticks < TimeSpan.MaxValue.Ticks - BufferedTimeInTicks)
{
return TimeSpan.FromTicks(timeout.Ticks + BufferedTimeInTicks);
}

return TimeSpan.MaxValue;
}

static void OnConnect(TransportAsyncCallbackArgs args)
{
ConnectAsyncResult thisPtr = (ConnectAsyncResult)args.UserToken;
Expand Down

0 comments on commit 8cc962e

Please sign in to comment.