Skip to content

Fix local failure in GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout #58747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1992,6 +1992,10 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
var readAsyncTask = new TaskCompletionSource<Task>(TaskCreationOptions.RunContinuationsAsynchronously);
var requestAbortedTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);

// Wait 2.5 seconds in debug (local development) and 15 seconds in production (CI)
// Use half the default timeout to ensure the host shuts down before the test throws an error while waiting.
var shutdownTimeout = Microsoft.AspNetCore.InternalTesting.TaskExtensions.DefaultTimeoutTimeSpan / 2;

var builder = CreateHostBuilder(async context =>
{
context.RequestAborted.Register(() => requestAbortedTcs.SetResult());
Expand Down Expand Up @@ -2021,7 +2025,8 @@ public async Task GET_GracefulServerShutdown_AbortRequestsAfterHostTimeout(HttpP
listenOptions.Protocols = protocol;
listenOptions.UseHttps(TestResources.GetTestCertificate());
});
});
},
shutdownTimeout: shutdownTimeout);

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

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

// Assert
Logger.LogInformation("Waiting for error from read task");
var ex = await Assert.ThrowsAnyAsync<Exception>(() => readTask).DefaultTimeout();
while (ex.InnerException != null)

var rootException = ex;
while (rootException.InnerException != null)
{
ex = ex.InnerException;
rootException = rootException.InnerException;
}

Assert.IsType<ConnectionAbortedException>(ex);
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);
Assert.IsType<ConnectionAbortedException>(rootException);
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);

await requestAbortedTcs.Task.DefaultTimeout();

Expand Down Expand Up @@ -2191,8 +2200,8 @@ public async Task ServerReset_InvalidErrorCode()
Assert.Equal(HttpStatusCode.InternalServerError, response.StatusCode);
}

private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null)
private IHostBuilder CreateHostBuilder(RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, TimeSpan? shutdownTimeout = null)
{
return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel);
return HttpHelpers.CreateHostBuilder(AddTestLogging, requestDelegate, protocol, configureKestrel, shutdownTimeout: shutdownTimeout);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static HttpMessageInvoker CreateClient(TimeSpan? idleTimeout = null, Time
return new HttpMessageInvoker(handler);
}

public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, bool? plaintext = null)
public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configureServices, RequestDelegate requestDelegate, HttpProtocols? protocol = null, Action<KestrelServerOptions> configureKestrel = null, bool? plaintext = null, TimeSpan? shutdownTimeout = null)
{
return new HostBuilder()
.ConfigureWebHost(webHostBuilder =>
Expand Down Expand Up @@ -102,7 +102,7 @@ public static IHostBuilder CreateHostBuilder(Action<IServiceCollection> configur
}
else
{
o.ShutdownTimeout = TimeSpan.FromSeconds(5);
o.ShutdownTimeout = shutdownTimeout ?? TimeSpan.FromSeconds(5);
}
});
}
Expand Down
Loading