Skip to content

Commit edcd274

Browse files
committed
Clean up
1 parent 0b8dd8f commit edcd274

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

src/Servers/Kestrel/Core/src/Internal/Http3/Http3Connection.cs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ internal class Http3Connection : IHttp3StreamLifetimeHandler, IRequestProcessor
4040
private int _stoppedAcceptingStreams;
4141
private bool _gracefulCloseStarted;
4242
private int _activeRequestCount;
43-
private readonly CancellationTokenSource _serverCloseCts;
43+
private readonly CancellationTokenSource _allRequestsCompleted;
4444
private readonly Http3PeerSettings _serverSettings = new Http3PeerSettings();
4545
private readonly Http3PeerSettings _clientSettings = new Http3PeerSettings();
4646
private readonly StreamCloseAwaitable _streamCompletionAwaitable = new StreamCloseAwaitable();
@@ -51,7 +51,7 @@ public Http3Connection(HttpMultiplexedConnectionContext context)
5151
_multiplexedContext = (MultiplexedConnectionContext)context.ConnectionContext;
5252
_context = context;
5353
_streamLifetimeHandler = this;
54-
_serverCloseCts = new CancellationTokenSource();
54+
_allRequestsCompleted = new CancellationTokenSource();
5555

5656
_errorCodeFeature = context.ConnectionFeatures.Get<IProtocolErrorCodeFeature>()!;
5757

@@ -237,7 +237,7 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> appl
237237

238238
while (true)
239239
{
240-
var streamContext = await _multiplexedContext.AcceptAsync(_serverCloseCts.Token);
240+
var streamContext = await _multiplexedContext.AcceptAsync(_allRequestsCompleted.Token);
241241

242242
try
243243
{
@@ -378,20 +378,14 @@ public async Task ProcessRequestsAsync<TContext>(IHttpApplication<TContext> appl
378378
}
379379
catch
380380
{
381-
Abort(ResolveConnectionError(error), Http3ErrorCode.InternalError);
381+
Abort(connectionError, Http3ErrorCode.InternalError);
382382
throw;
383383
}
384384
finally
385385
{
386386
Log.Http3ConnectionClosed(_context.ConnectionId, GetHighestStreamId());
387387
}
388388
}
389-
390-
static ConnectionAbortedException ResolveConnectionError(Exception? error)
391-
{
392-
return error as ConnectionAbortedException
393-
?? new ConnectionAbortedException(CoreStrings.Http3ConnectionFaulted, error!);
394-
}
395389
}
396390

397391
private Http3StreamContext CreateHttpStreamContext(ConnectionContext streamContext)
@@ -583,9 +577,14 @@ void IHttp3StreamLifetimeHandler.OnStreamCompleted(IHttp3Stream stream)
583577
}
584578
_streams.Remove(stream.StreamId);
585579

586-
if (_gracefulCloseStarted)
580+
if (stream.IsRequestStream)
587581
{
588-
_serverCloseCts.Cancel();
582+
// Connection is gracefully closing and this is the final request.
583+
// Trigger cancellation token to cause AcceptAsync to exit.
584+
if (_gracefulCloseStarted && _activeRequestCount == 0)
585+
{
586+
_allRequestsCompleted.Cancel();
587+
}
589588
}
590589
}
591590

src/Servers/Kestrel/test/Interop.FunctionalTests/Http3/Http3RequestTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,12 +1148,12 @@ private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProt
11481148
.ConfigureServices(AddTestLogging)
11491149
.ConfigureHostOptions(o =>
11501150
{
1151-
//if (Debugger.IsAttached)
1152-
//{
1153-
// // Avoid timeout while debugging.
1154-
// o.ShutdownTimeout = TimeSpan.FromHours(1);
1155-
//}
1156-
//else
1151+
if (Debugger.IsAttached)
1152+
{
1153+
// Avoid timeout while debugging.
1154+
o.ShutdownTimeout = TimeSpan.FromHours(1);
1155+
}
1156+
else
11571157
{
11581158
o.ShutdownTimeout = TimeSpan.FromSeconds(1);
11591159
}

0 commit comments

Comments
 (0)