Skip to content

Commit 71aaedc

Browse files
committed
Update
1 parent 8ecbe6c commit 71aaedc

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,15 +453,27 @@ private async ValueTask<Http3ControlStream> CreateNewUnidirectionalStreamAsync<T
453453
return new Http3ControlStream<TContext>(application, httpConnectionContext);
454454
}
455455

456-
private ValueTask<FlushResult> SendGoAway(long id)
456+
private async ValueTask<FlushResult> SendGoAway(long id)
457457
{
458+
Http3ControlStream? stream;
458459
lock (_sync)
459460
{
460-
if (OutboundControlStream != null)
461+
stream = OutboundControlStream;
462+
}
463+
464+
if (stream != null)
465+
{
466+
try
461467
{
462-
return OutboundControlStream.SendGoAway(id);
468+
return await stream.SendGoAway(id);
469+
}
470+
catch
471+
{
472+
// The control stream may not be healthy.
473+
// Ignore error sending go away.
463474
}
464475
}
476+
465477
return default;
466478
}
467479

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3ConnectionTests.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,15 @@ await WaitForConnectionErrorAsync<Http3ConnectionErrorException>(
160160
[Fact]
161161
public async Task ControlStream_ServerToClient_ErrorInitializing_ConnectionError()
162162
{
163-
OnCreateServerControlStream = () => throw new Exception();
163+
OnCreateServerControlStream = () =>
164+
{
165+
var controlStream = new Http3ControlStream(this, StreamInitiator.Server);
166+
167+
// Make server connection error when trying to write to control stream.
168+
controlStream.StreamContext.Transport.Output.Complete();
169+
170+
return controlStream;
171+
};
164172

165173
await InitializeConnectionAsync(_noopApplication);
166174

src/Servers/Kestrel/test/InMemory.FunctionalTests/Http3/Http3TestBase.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,16 @@ internal async ValueTask<Http3ControlStream> GetInboundControlStream()
187187
if (_inboundControlStream == null)
188188
{
189189
var reader = MultiplexedConnectionContext.ToClientAcceptQueue.Reader;
190-
while (await reader.WaitToReadAsync())
190+
while (await reader.WaitToReadAsync().DefaultTimeout())
191191
{
192192
while (reader.TryRead(out var stream))
193193
{
194194
_inboundControlStream = stream;
195195
var streamId = await stream.TryReadStreamIdAsync();
196-
Debug.Assert(streamId == 0, "StreamId sent that was non-zero, which isn't handled by tests");
196+
197+
// -1 means stream was completed.
198+
Debug.Assert(streamId == 0 || streamId == -1, "StreamId sent that was non-zero, which isn't handled by tests");
199+
197200
return _inboundControlStream;
198201
}
199202
}

0 commit comments

Comments
 (0)