Skip to content

Commit 5a24514

Browse files
committed
Make sure corresponding Connection and Channel token properly float into handlers
1 parent 44d8be3 commit 5a24514

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

projects/RabbitMQ.Client/Impl/Channel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ protected void TakeOver(Channel other)
201201
public Task CloseAsync(ushort replyCode, string replyText, bool abort,
202202
CancellationToken cancellationToken)
203203
{
204-
var args = new ShutdownEventArgs(ShutdownInitiator.Application, replyCode, replyText);
204+
var args = new ShutdownEventArgs(ShutdownInitiator.Application, replyCode, replyText, cancellationToken: cancellationToken);
205205
return CloseAsync(args, abort, cancellationToken);
206206
}
207207

@@ -850,7 +850,7 @@ await Session.Connection.HandleConnectionBlockedAsync(reason, cancellationToken)
850850
protected async Task<bool> HandleConnectionCloseAsync(IncomingCommand cmd, CancellationToken cancellationToken)
851851
{
852852
var method = new ConnectionClose(cmd.MethodSpan);
853-
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId);
853+
var reason = new ShutdownEventArgs(ShutdownInitiator.Peer, method._replyCode, method._replyText, method._classId, method._methodId, cancellationToken: cancellationToken);
854854
try
855855
{
856856
/*
@@ -895,7 +895,7 @@ protected async Task<bool> HandleConnectionStartAsync(IncomingCommand cmd, Cance
895895
{
896896
if (m_connectionStartCell is null)
897897
{
898-
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start");
898+
var reason = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.CommandInvalid, "Unexpected Connection.Start", cancellationToken: cancellationToken);
899899
await Session.Connection.CloseAsync(reason, false,
900900
InternalConstants.DefaultConnectionCloseTimeout,
901901
cancellationToken)

projects/RabbitMQ.Client/Impl/Connection.Receive.cs

Lines changed: 10 additions & 5 deletions
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
}

projects/RabbitMQ.Client/Impl/Connection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ await _channel0.ConnectionOpenAsync(_config.VirtualHost, cancellationToken)
254254
{
255255
try
256256
{
257-
var ea = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.InternalError, "FailedOpen");
257+
var ea = new ShutdownEventArgs(ShutdownInitiator.Library, Constants.InternalError, "FailedOpen", cancellationToken: cancellationToken);
258258
await CloseAsync(ea, true,
259259
InternalConstants.DefaultConnectionAbortTimeout,
260260
cancellationToken).ConfigureAwait(false);
@@ -299,7 +299,7 @@ internal void EnsureIsOpen()
299299
public Task CloseAsync(ushort reasonCode, string reasonText, TimeSpan timeout, bool abort,
300300
CancellationToken cancellationToken = default)
301301
{
302-
var reason = new ShutdownEventArgs(ShutdownInitiator.Application, reasonCode, reasonText);
302+
var reason = new ShutdownEventArgs(ShutdownInitiator.Application, reasonCode, reasonText, cancellationToken: cancellationToken);
303303
return CloseAsync(reason, abort, timeout, cancellationToken);
304304
}
305305

0 commit comments

Comments
 (0)