@@ -11,9 +11,6 @@ namespace RabbitMQ.Client.ConsumerDispatching
11
11
#nullable enable
12
12
internal abstract class ConsumerDispatcherChannelBase : ConsumerDispatcherBase , IConsumerDispatcher
13
13
{
14
- protected readonly CancellationTokenSource _consumerDispatcherCts = new CancellationTokenSource ( ) ;
15
- protected readonly CancellationToken _consumerDispatcherToken ;
16
-
17
14
protected readonly ChannelBase _channel ;
18
15
protected readonly ChannelReader < WorkStruct > _reader ;
19
16
private readonly ChannelWriter < WorkStruct > _writer ;
@@ -23,7 +20,6 @@ internal abstract class ConsumerDispatcherChannelBase : ConsumerDispatcherBase,
23
20
24
21
internal ConsumerDispatcherChannelBase ( ChannelBase channel , int concurrency )
25
22
{
26
- _consumerDispatcherToken = _consumerDispatcherCts . Token ;
27
23
_channel = channel ;
28
24
var workChannel = Channel . CreateUnbounded < WorkStruct > ( new UnboundedChannelOptions
29
25
{
@@ -34,18 +30,17 @@ internal ConsumerDispatcherChannelBase(ChannelBase channel, int concurrency)
34
30
_reader = workChannel . Reader ;
35
31
_writer = workChannel . Writer ;
36
32
37
- Func < Task > loopStart =
38
- ( ) => ProcessChannelAsync ( _consumerDispatcherToken ) ;
33
+ Func < Task > loopStart = ProcessChannelAsync ;
39
34
if ( concurrency == 1 )
40
35
{
41
- _worker = Task . Run ( loopStart , _consumerDispatcherToken ) ;
36
+ _worker = Task . Run ( loopStart ) ;
42
37
}
43
38
else
44
39
{
45
40
var tasks = new Task [ concurrency ] ;
46
41
for ( int i = 0 ; i < concurrency ; i ++ )
47
42
{
48
- tasks [ i ] = Task . Run ( loopStart , _consumerDispatcherToken ) ;
43
+ tasks [ i ] = Task . Run ( loopStart ) ;
49
44
}
50
45
_worker = Task . WhenAll ( tasks ) ;
51
46
}
@@ -122,21 +117,6 @@ public void Quiesce()
122
117
_quiesce = true ;
123
118
}
124
119
125
- private bool IsCancellationRequested
126
- {
127
- get
128
- {
129
- try
130
- {
131
- return _consumerDispatcherCts . IsCancellationRequested ;
132
- }
133
- catch ( ObjectDisposedException )
134
- {
135
- return true ;
136
- }
137
- }
138
- }
139
-
140
120
public void WaitForShutdown ( )
141
121
{
142
122
if ( _disposed )
@@ -146,40 +126,37 @@ public void WaitForShutdown()
146
126
147
127
if ( _quiesce )
148
128
{
149
- if ( IsCancellationRequested )
129
+ try
150
130
{
151
- try
131
+ if ( false == _reader . Completion . Wait ( TimeSpan . FromSeconds ( 2 ) ) )
152
132
{
153
- if ( false == _reader . Completion . Wait ( TimeSpan . FromSeconds ( 2 ) ) )
154
- {
155
- ESLog . Warn ( "consumer dispatcher did not shut down in a timely fashion (sync)" ) ;
156
- }
157
- if ( false == _worker . Wait ( TimeSpan . FromSeconds ( 2 ) ) )
158
- {
159
- ESLog . Warn ( "consumer dispatcher did not shut down in a timely fashion (sync)" ) ;
160
- }
133
+ ESLog . Warn ( "consumer dispatcher did not shut down in a timely fashion (sync)" ) ;
161
134
}
162
- catch ( AggregateException aex )
135
+ if ( false == _worker . Wait ( TimeSpan . FromSeconds ( 2 ) ) )
163
136
{
164
- AggregateException aexf = aex . Flatten ( ) ;
165
- bool foundUnexpectedException = false ;
166
- foreach ( Exception innerAexf in aexf . InnerExceptions )
167
- {
168
- if ( false == ( innerAexf is OperationCanceledException ) )
169
- {
170
- foundUnexpectedException = true ;
171
- break ;
172
- }
173
- }
174
- if ( foundUnexpectedException )
137
+ ESLog . Warn ( "consumer dispatcher did not shut down in a timely fashion (sync)" ) ;
138
+ }
139
+ }
140
+ catch ( AggregateException aex )
141
+ {
142
+ AggregateException aexf = aex . Flatten ( ) ;
143
+ bool foundUnexpectedException = false ;
144
+ foreach ( Exception innerAexf in aexf . InnerExceptions )
145
+ {
146
+ if ( false == ( innerAexf is OperationCanceledException ) )
175
147
{
176
- ESLog . Warn ( "consumer dispatcher task had unexpected exceptions" ) ;
148
+ foundUnexpectedException = true ;
149
+ break ;
177
150
}
178
151
}
179
- catch ( OperationCanceledException )
152
+ if ( foundUnexpectedException )
180
153
{
154
+ ESLog . Warn ( "consumer dispatcher task had unexpected exceptions" ) ;
181
155
}
182
156
}
157
+ catch ( OperationCanceledException )
158
+ {
159
+ }
183
160
}
184
161
else
185
162
{
@@ -238,17 +215,15 @@ protected sealed override void ShutdownConsumer(IBasicConsumer consumer, Shutdow
238
215
protected override void InternalShutdown ( )
239
216
{
240
217
_writer . Complete ( ) ;
241
- CancelConsumerDispatcherCts ( ) ;
242
218
}
243
219
244
220
protected override Task InternalShutdownAsync ( )
245
221
{
246
222
_writer . Complete ( ) ;
247
- CancelConsumerDispatcherCts ( ) ;
248
223
return _worker ;
249
224
}
250
225
251
- protected abstract Task ProcessChannelAsync ( CancellationToken token ) ;
226
+ protected abstract Task ProcessChannelAsync ( ) ;
252
227
253
228
protected readonly struct WorkStruct : IDisposable
254
229
{
@@ -334,17 +309,6 @@ protected enum WorkType : byte
334
309
ConsumeOk
335
310
}
336
311
337
- protected void CancelConsumerDispatcherCts ( )
338
- {
339
- try
340
- {
341
- _consumerDispatcherCts . Cancel ( ) ;
342
- }
343
- catch ( ObjectDisposedException )
344
- {
345
- }
346
- }
347
-
348
312
protected virtual void Dispose ( bool disposing )
349
313
{
350
314
if ( ! _disposed )
@@ -354,8 +318,6 @@ protected virtual void Dispose(bool disposing)
354
318
if ( disposing )
355
319
{
356
320
Quiesce ( ) ;
357
- CancelConsumerDispatcherCts ( ) ;
358
- _consumerDispatcherCts . Dispose ( ) ;
359
321
}
360
322
}
361
323
catch
0 commit comments