-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
IHostBuilder.Build() times out when debugging startup with minimal hosting and WebApplicationFactory<T> #33886
Comments
Yes this is a good catch, I've been meaning to make this not timeout at all when the debugger is attached (Timeout.InfiniteTimeSpan) |
I'm digging into #33876 locally at the moment (which is what prompted this issue) and I have the following in it locally. var deferredHostBuilder = new DeferredHostBuilder();
var waitTimeout = new TimeSpan?();
if (Debugger.IsAttached)
{
waitTimeout = Timeout.InfiniteTimeSpan;
}
// This helper call does the hard work to determine if we can fallback to diagnostic source events to get the host instance
var factory = HostFactoryResolver.ResolveHostFactory(
typeof(TEntryPoint).Assembly,
waitTimeout,
stopApplication: false,
configureHostBuilder: deferredHostBuilder.ConfigureHostBuilder,
entrypointCompleted: deferredHostBuilder.EntryPointCompleted); I wasn't sure what heuristic was preferred for "is it debug time?" in case there was some nuance to it like with "is development?" so didn't suggest a specific fix. If the above is what you'd want to do anyway, I'd be happy to push up a PR as a fix candidate for this. |
I would make it in dotnet/runtime |
Cool I'll do that shortly then 👍 |
Do not timeout waiting for the host to start when running with the debugger attached. Addresses dotnet/aspnetcore#33886.
Do not timeout waiting for the host to start when running with the debugger attached. Addresses dotnet/aspnetcore#33886.
Done via dotnet/runtime#54791 |
Describe the bug
When debugging startup paths when using
WebApplicationBuilder
for hosting andWebApplicationFactory<T>
for testing, if more than 5 seconds elapses (which is likely when debugging in an IDE), then theIHost
will fail to build and thow anInvalidOperationException
with the messageUnable to build IHost
.This appears to be because no explicit timeout is passed for the
waitTimeout
parameter of the call toResolveHostFactory()
here:aspnetcore/src/Mvc/Mvc.Testing/src/WebApplicationFactory.cs
Lines 164 to 168 in dbf84ea
This leads to the default timeout of 5 seconds being used.
An appropriate higher (or infinite) timeout should be used when debugging so that after debugging startup code the host will start successfully.
To Reproduce
Run the following unit test with the debugger attached:
App code:
Exceptions (if any)
Further technical details
6.0.0-preview.6.21323.4
6.0.100-preview.6.21324.1
The text was updated successfully, but these errors were encountered: