Skip to content

Commit 5da1089

Browse files
committed
* Ensure that dequeued RPC continuations are always disposed. Found by @DenisMayorko
1 parent 0ab9f04 commit 5da1089

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

Diff for: projects/Applications/CreateChannel/Program.cs

-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,6 @@ public static async Task Main()
8585
Console.WriteLine($"{channelsOpened,5}");
8686
Console.WriteLine();
8787
Console.WriteLine($"Took {watch.Elapsed.TotalMilliseconds} ms");
88-
89-
Console.ReadLine();
9088
}
9189
}
9290
}

Diff for: projects/RabbitMQ.Client/Impl/Channel.cs

+12-8
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,13 @@ protected async Task<bool> HandleChannelCloseOkAsync(IncomingCommand cmd, Cancel
744744
await FinishCloseAsync(cancellationToken)
745745
.ConfigureAwait(false);
746746

747-
if (_continuationQueue.TryPeek<ChannelCloseAsyncRpcContinuation>(out ChannelCloseAsyncRpcContinuation? k))
747+
if (_continuationQueue.TryPeek(out ChannelCloseAsyncRpcContinuation? k))
748748
{
749-
_continuationQueue.Next();
750-
await k.HandleCommandAsync(cmd)
751-
.ConfigureAwait(false);
749+
using (IRpcContinuation c = _continuationQueue.Next())
750+
{
751+
await k.HandleCommandAsync(cmd)
752+
.ConfigureAwait(false);
753+
}
752754
}
753755

754756
return true;
@@ -818,10 +820,12 @@ await ModelSendAsync(in replyMethod, cancellationToken)
818820

819821
protected async Task<bool> HandleConnectionSecureAsync(IncomingCommand cmd, CancellationToken cancellationToken)
820822
{
821-
var k = (ConnectionSecureOrTuneAsyncRpcContinuation)_continuationQueue.Next();
822-
await k.HandleCommandAsync(new IncomingCommand())
823-
.ConfigureAwait(false); // release the continuation.
824-
return true;
823+
using (var k = (ConnectionSecureOrTuneAsyncRpcContinuation)_continuationQueue.Next())
824+
{
825+
await k.HandleCommandAsync(new IncomingCommand())
826+
.ConfigureAwait(false); // release the continuation.
827+
return true;
828+
}
825829
}
826830

827831
protected async Task<bool> HandleConnectionStartAsync(IncomingCommand cmd, CancellationToken cancellationToken)

Diff for: projects/RabbitMQ.Client/Impl/RpcContinuationQueue.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,10 @@ public void Enqueue(IRpcContinuation k)
9797
///</remarks>
9898
public void HandleChannelShutdown(ShutdownEventArgs reason)
9999
{
100-
Next().HandleChannelShutdown(reason);
100+
using (IRpcContinuation c = Next())
101+
{
102+
c.HandleChannelShutdown(reason);
103+
}
101104
}
102105

103106
///<summary>Retrieve the next waiting continuation.</summary>

0 commit comments

Comments
 (0)