Skip to content

Commit dc68e3b

Browse files
authored
Fix local failure in GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout (#58747)
1 parent 6f8fb16 commit dc68e3b

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

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

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,6 +1992,10 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
19921992
var readAsyncTask = new TaskCompletionSource<Task>(TaskCreationOptions.RunContinuationsAsynchronously);
19931993
var requestAbortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
19941994

1995+
// Wait 2.5 seconds in debug (local development) and 15 seconds in production (CI)
1996+
// Use half the default timeout to ensure the host shuts down before the test throws an error while waiting.
1997+
var shutdownTimeout = Microsoft.AspNetCore.InternalTesting.TaskExtensions.DefaultTimeoutTimeSpan / 2;
1998+
19951999
var builder = CreateHostBuilder(async context =>
19962000
{
19972001
context.RequestAborted.Register(() => requestAbortedTcs.SetResult());
@@ -2021,7 +2025,8 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
20212025
listenOptions.Protocols = protocol;
20222026
listenOptions.UseHttps(TestResources.GetTestCertificate());
20232027
});
2024-
});
2028+
},
2029+
shutdownTimeout: shutdownTimeout);
20252030

20262031
using (var host = builder.Build())
20272032
using (var client = HttpHelpers.CreateClient())
@@ -2061,17 +2066,21 @@ await WaitForLogAsync(logs =>
20612066
}, "Check for initial GOAWAY frame sent on server initiated shutdown.");
20622067
}
20632068

2069+
Logger.LogInformation("Getting read task");
20642070
var readTask = await readAsyncTask.Task.DefaultTimeout();
20652071

20662072
// Assert
2073+
Logger.LogInformation("Waiting for error from read task");
20672074
var ex = await Assert.ThrowsAnyAsync<Exception>(() => readTask).DefaultTimeout();
2068-
while (ex.InnerException != null)
2075+
2076+
var rootException = ex;
2077+
while (rootException.InnerException != null)
20692078
{
2070-
ex = ex.InnerException;
2079+
rootException = rootException.InnerException;
20712080
}
20722081

2073-
Assert.IsType<ConnectionAbortedException>(ex);
2074-
Assert.Equal("The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout.", ex.Message);
2082+
Assert.IsType<ConnectionAbortedException>(rootException);
2083+
Assert.Equal("The connection was aborted because the server is shutting down and request processing didn't complete within the time specified by HostOptions.ShutdownTimeout.", rootException.Message);
20752084

20762085
await requestAbortedTcs.Task.DefaultTimeout();
20772086

@@ -2191,8 +2200,8 @@ public async Task ServerReset_InvalidErrorCode()
21912200
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
21922201
}
21932202

2194-
private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null)
2203+
private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, TimeSpan? shutdownTimeout = null)
21952204
{
2196-
return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel);
2205+
return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel, shutdownTimeout: shutdownTimeout);
21972206
}
21982207
}

src/Servers/Kestrel/test/Interop.FunctionalTests/HttpHelpers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public static HttpMessageInvoker CreateClient(TimeSpan? idleTimeout = null, Time
6363
return new HttpMessageInvoker(handler);
6464
}
6565

66-
public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, bool? plaintext = null)
66+
public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, bool? plaintext = null, TimeSpan? shutdownTimeout = null)
6767
{
6868
return new HostBuilder()
6969
.ConfigureWebHost(webHostBuilder =>
@@ -102,7 +102,7 @@ public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configur
102102
}
103103
else
104104
{
105-
o.ShutdownTimeout = TimeSpan.FromSeconds(5);
105+
o.ShutdownTimeout = shutdownTimeout ?? TimeSpan.FromSeconds(5);
106106
}
107107
});
108108
}

0 commit comments

Comments
 (0)