Skip to content

Commit 0413438

Browse files
committed
Make sure corresponding Connection and Channel token properly float into handlers
1 parent e4e05a0 commit 0413438

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ protected void TakeOver(Channel other)
196196
public Task CloseAsync(ushort replyCode, string replyText, bool abort,
197197
CancellationToken cancellationToken)
198198
{
199-
var args = new ShutdownEventArgs(ShutdownInitiator.Application, replyCode, replyText);
199+
var args = new ShutdownEventArgs(ShutdownInitiator.Application, replyCode, replyText, cancellationToken: cancellationToken);
200200
return CloseAsync(args, abort, cancellationToken);
201201
}
202202

@@ -725,7 +725,7 @@ await Session.Connection.HandleConnectionBlockedAsync(reason, cancellationToken)
725725
protected async Task<bool> HandleConnectionCloseAsync(IncomingCommand cmd, CancellationToken cancellationToken)
726726
{
727727
var method = new ConnectionClose(cmd.MethodSpan);
728-
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId);
728+
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId, cancellationToken: cancellationToken);
729729
try
730730
{
731731
await Session.Connection.ClosedViaPeerAsync(reason, cancellationToken)
@@ -763,7 +763,7 @@ protected async Task<bool> HandleConnectionStartAsync(IncomingCommand cmd, Cance
763763
{
764764
if (m_connectionStartCell is null)
765765
{
766-
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start");
766+
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start", cancellationToken: cancellationToken);
767767
await Session.Connection.CloseAsync(reason, false,
768768
InternalConstants.DefaultConnectionCloseTimeout,
769769
cancellationToken)

Diff for: projects/RabbitMQ.Client/Impl/Connection.Receive.cs

+10-5
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ await ReceiveLoopAsync(mainLoopToken)
6262
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
6363
Constants.InternalError,
6464
"Thread aborted (AppDomain unloaded?)",
65-
exception: taex);
65+
exception: taex,
66+
cancellationToken: mainLoopToken);
6667
await HandleMainLoopExceptionAsync(ea)
6768
.ConfigureAwait(false);
6869
}
@@ -73,7 +74,8 @@ await HandleMainLoopExceptionAsync(ea)
7374
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
7475
0,
7576
"End of stream",
76-
exception: eose);
77+
exception: eose,
78+
cancellationToken: mainLoopToken);
7779
await HandleMainLoopExceptionAsync(ea)
7880
.ConfigureAwait(false);
7981
}
@@ -91,7 +93,8 @@ await HardProtocolExceptionHandlerAsync(hpe, mainLoopToken)
9193
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
9294
Constants.InternalError,
9395
fileLoadException.Message,
94-
exception: fileLoadException);
96+
exception: fileLoadException,
97+
cancellationToken: mainLoopToken);
9598
await HandleMainLoopExceptionAsync(ea)
9699
.ConfigureAwait(false);
97100
}
@@ -106,7 +109,8 @@ await HandleMainLoopExceptionAsync(ea)
106109
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
107110
Constants.InternalError,
108111
ocex.Message,
109-
exception: ocex);
112+
exception: ocex,
113+
cancellationToken: mainLoopToken);
110114
await HandleMainLoopExceptionAsync(ea)
111115
.ConfigureAwait(false);
112116
}
@@ -116,7 +120,8 @@ await HandleMainLoopExceptionAsync(ea)
116120
var ea = new ShutdownEventArgs(ShutdownInitiator.Library,
117121
Constants.InternalError,
118122
ex.Message,
119-
exception: ex);
123+
exception: ex,
124+
cancellationToken: mainLoopToken);
120125
await HandleMainLoopExceptionAsync(ea)
121126
.ConfigureAwait(false);
122127
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ await _channel0.ConnectionOpenAsync(_config.VirtualHost, cancellationToken)
252252
{
253253
try
254254
{
255-
var ea = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.InternalError, "FailedOpen");
255+
var ea = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.InternalError, "FailedOpen", cancellationToken: cancellationToken);
256256
await CloseAsync(ea, true,
257257
InternalConstants.DefaultConnectionAbortTimeout,
258258
cancellationToken).ConfigureAwait(false);
@@ -297,7 +297,7 @@ internal void EnsureIsOpen()
297297
public Task CloseAsync(ushort reasonCode, string reasonText, TimeSpan timeout, bool abort,
298298
CancellationToken cancellationToken = default)
299299
{
300-
var reason = new ShutdownEventArgs(ShutdownInitiator.Application, reasonCode, reasonText);
300+
var reason = new ShutdownEventArgs(ShutdownInitiator.Application, reasonCode, reasonText, cancellationToken: cancellationToken);
301301
return CloseAsync(reason, abort, timeout, cancellationToken);
302302
}
303303

0 commit comments

Comments
 (0)