@@ -33,7 +33,6 @@ public class HubConnectionContext
33
33
34
34
private long _lastSendTimestamp = Stopwatch . GetTimestamp ( ) ;
35
35
private ReadOnlyMemory < byte > _cachedPingMessage ;
36
- private volatile bool _connectionAborted ;
37
36
38
37
/// <summary>
39
38
/// Initializes a new instance of the <see cref="HubConnectionContext"/> class.
@@ -100,12 +99,6 @@ public virtual ValueTask WriteAsync(HubMessage message, CancellationToken cancel
100
99
return new ValueTask ( WriteSlowAsync ( message ) ) ;
101
100
}
102
101
103
- if ( _connectionAborted )
104
- {
105
- _writeLock . Release ( ) ;
106
- return default ;
107
- }
108
-
109
102
// This method should never throw synchronously
110
103
var task = WriteCore ( message ) ;
111
104
@@ -136,12 +129,6 @@ public virtual ValueTask WriteAsync(SerializedHubMessage message, CancellationTo
136
129
return new ValueTask ( WriteSlowAsync ( message ) ) ;
137
130
}
138
131
139
- if ( _connectionAborted )
140
- {
141
- _writeLock . Release ( ) ;
142
- return default ;
143
- }
144
-
145
132
// This method should never throw synchronously
146
133
var task = WriteCore ( message ) ;
147
134
@@ -171,8 +158,6 @@ private ValueTask<FlushResult> WriteCore(HubMessage message)
171
158
{
172
159
Log . FailedWritingMessage ( _logger , ex ) ;
173
160
174
- Abort ( ) ;
175
-
176
161
return new ValueTask < FlushResult > ( new FlushResult ( isCanceled : false , isCompleted : true ) ) ;
177
162
}
178
163
}
@@ -190,8 +175,6 @@ private ValueTask<FlushResult> WriteCore(SerializedHubMessage message)
190
175
{
191
176
Log . FailedWritingMessage ( _logger , ex ) ;
192
177
193
- Abort ( ) ;
194
-
195
178
return new ValueTask < FlushResult > ( new FlushResult ( isCanceled : false , isCompleted : true ) ) ;
196
179
}
197
180
}
@@ -205,8 +188,6 @@ private async Task CompleteWriteAsync(ValueTask<FlushResult> task)
205
188
catch ( Exception ex )
206
189
{
207
190
Log . FailedWritingMessage ( _logger , ex ) ;
208
-
209
- Abort ( ) ;
210
191
}
211
192
finally
212
193
{
@@ -220,20 +201,13 @@ private async Task WriteSlowAsync(HubMessage message)
220
201
await _writeLock . WaitAsync ( ) ;
221
202
try
222
203
{
223
- if ( _connectionAborted )
224
- {
225
- return ;
226
- }
227
-
228
204
// Failed to get the lock immediately when entering WriteAsync so await until it is available
229
205
230
206
await WriteCore ( message ) ;
231
207
}
232
208
catch ( Exception ex )
233
209
{
234
210
Log . FailedWritingMessage ( _logger , ex ) ;
235
-
236
- Abort ( ) ;
237
211
}
238
212
finally
239
213
{
@@ -245,11 +219,6 @@ private async Task WriteSlowAsync(SerializedHubMessage message)
245
219
{
246
220
try
247
221
{
248
- if ( _connectionAborted )
249
- {
250
- return ;
251
- }
252
-
253
222
// Failed to get the lock immediately when entering WriteAsync so await until it is available
254
223
await _writeLock . WaitAsync ( ) ;
255
224
@@ -258,8 +227,6 @@ private async Task WriteSlowAsync(SerializedHubMessage message)
258
227
catch ( Exception ex )
259
228
{
260
229
Log . FailedWritingMessage ( _logger , ex ) ;
261
-
262
- Abort ( ) ;
263
230
}
264
231
finally
265
232
{
@@ -283,20 +250,13 @@ private async Task TryWritePingSlowAsync()
283
250
{
284
251
try
285
252
{
286
- if ( _connectionAborted )
287
- {
288
- return ;
289
- }
290
-
291
253
await _connectionContext . Transport . Output . WriteAsync ( _cachedPingMessage ) ;
292
254
293
255
Log . SentPing ( _logger ) ;
294
256
}
295
257
catch ( Exception ex )
296
258
{
297
259
Log . FailedWritingMessage ( _logger , ex ) ;
298
-
299
- Abort ( ) ;
300
260
}
301
261
finally
302
262
{
@@ -333,12 +293,6 @@ private async Task WriteHandshakeResponseAsync(HandshakeResponseMessage message)
333
293
/// </summary>
334
294
public virtual void Abort ( )
335
295
{
336
- _connectionAborted = true ;
337
-
338
- // Cancel any current writes or writes that are about to happen and have already gone past the _connectionAborted bool
339
- // We have to do this outside of the lock otherwise it could hang if the write is observing backpressure
340
- _connectionContext . Transport . Output . CancelPendingFlush ( ) ;
341
-
342
296
// If we already triggered the token then noop, this isn't thread safe but it's good enough
343
297
// to avoid spawning a new task in the most common cases
344
298
if ( _connectionAbortedTokenSource . IsCancellationRequested )
@@ -469,24 +423,9 @@ internal void Abort(Exception exception)
469
423
internal Task AbortAsync ( )
470
424
{
471
425
Abort ( ) ;
472
-
473
- // Acquire lock to make sure all writes are completed
474
- if ( ! _writeLock . Wait ( 0 ) )
475
- {
476
- return AbortAsyncSlow ( ) ;
477
- }
478
-
479
- _writeLock . Release ( ) ;
480
426
return _abortCompletedTcs . Task ;
481
427
}
482
428
483
- private async Task AbortAsyncSlow ( )
484
- {
485
- await _writeLock . WaitAsync ( ) ;
486
- _writeLock . Release ( ) ;
487
- await _abortCompletedTcs . Task ;
488
- }
489
-
490
429
private void KeepAliveTick ( )
491
430
{
492
431
var timestamp = Stopwatch . GetTimestamp ( ) ;
0 commit comments