@@ -43,7 +43,7 @@ public partial class Frame : FrameContext, IFrameControl
43
43
private Task _requestProcessingTask ;
44
44
private volatile bool _requestProcessingStopping ; // volatile, see: https://msdn.microsoft.com/en-us/library/x13ttww7.aspx
45
45
private volatile bool _requestAborted ;
46
- private CancellationTokenSource _disconnectOrAbortedCts = new CancellationTokenSource ( ) ;
46
+ private CancellationTokenSource _abortedCts ;
47
47
48
48
private FrameRequestStream _requestBody ;
49
49
private FrameResponseStream _responseBody ;
@@ -144,6 +144,9 @@ public void Reset()
144
144
}
145
145
146
146
_prepareRequest ? . Invoke ( this ) ;
147
+
148
+ _abortedCts ? . Dispose ( ) ;
149
+ _abortedCts = null ;
147
150
}
148
151
149
152
public void ResetResponseHeaders ( )
@@ -196,12 +199,17 @@ public void Abort()
196
199
ConnectionControl . End ( ProduceEndType . SocketDisconnect ) ;
197
200
SocketInput . AbortAwaiting ( ) ;
198
201
199
- _disconnectOrAbortedCts . Cancel ( ) ;
202
+ _abortedCts ? . Cancel ( ) ;
200
203
}
201
204
catch ( Exception ex )
202
205
{
203
206
Log . LogError ( "Abort" , ex ) ;
204
207
}
208
+ finally
209
+ {
210
+ _abortedCts ? . Dispose ( ) ;
211
+ _abortedCts = null ;
212
+ }
205
213
}
206
214
207
215
/// <summary>
@@ -245,7 +253,8 @@ public async Task RequestProcessingAsync()
245
253
ResponseBody = _responseBody ;
246
254
DuplexStream = new FrameDuplexStream ( RequestBody , ResponseBody ) ;
247
255
248
- RequestAborted = _disconnectOrAbortedCts . Token ;
256
+ _abortedCts = new CancellationTokenSource ( ) ;
257
+ RequestAborted = _abortedCts . Token ;
249
258
250
259
var httpContext = HttpContextFactory . Create ( this ) ;
251
260
try
@@ -298,7 +307,8 @@ public async Task RequestProcessingAsync()
298
307
{
299
308
try
300
309
{
301
- _disconnectOrAbortedCts . Dispose ( ) ;
310
+ _abortedCts ? . Dispose ( ) ;
311
+ _abortedCts = null ;
302
312
303
313
// If _requestAborted is set, the connection has already been closed.
304
314
if ( ! _requestAborted )
0 commit comments