Skip to content

Commit 49ee958

Browse files
Do not timeout HostingListener when debugging (#54791)
Do not timeout waiting for the host to start when running with the debugger attached. Addresses dotnet/aspnetcore#33886.
1 parent 385b6f3 commit 49ee958

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

src/libraries/Microsoft.Extensions.HostFactoryResolver/src/HostFactoryResolver.cs

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal sealed class HostFactoryResolver
2121
public const string CreateHostBuilder = nameof(CreateHostBuilder);
2222

2323
// The amount of time we wait for the diagnostic source events to fire
24-
private static readonly TimeSpan s_defaultWaitTimeout = TimeSpan.FromSeconds(5);
24+
private static readonly TimeSpan s_defaultWaitTimeout = Debugger.IsAttached ? Timeout.InfiniteTimeSpan : TimeSpan.FromSeconds(5);
2525

2626
public static Func<string[], TWebHost>? ResolveWebHostFactory<TWebHost>(Assembly assembly)
2727
{
@@ -44,10 +44,10 @@ internal sealed class HostFactoryResolver
4444
// 3. Give the caller a chance to execute logic to mutate the IHostBuilder
4545
// 4. Resolve the instance of the applications's IHost
4646
// 5. Allow the caller to determine if the entry point has completed
47-
public static Func<string[], object>? ResolveHostFactory(Assembly assembly,
48-
TimeSpan? waitTimeout = null,
49-
bool stopApplication = true,
50-
Action<object>? configureHostBuilder = null,
47+
public static Func<string[], object>? ResolveHostFactory(Assembly assembly,
48+
TimeSpan? waitTimeout = null,
49+
bool stopApplication = true,
50+
Action<object>? configureHostBuilder = null,
5151
Action<Exception?>? entrypointCompleted = null)
5252
{
5353
if (assembly.EntryPoint is null)
@@ -64,7 +64,7 @@ internal sealed class HostFactoryResolver
6464
{
6565
return null;
6666
}
67-
67+
6868
// We're using a version >= 6 so the events can fire. If they don't fire
6969
// then it's because the application isn't using the hosting APIs
7070
}
@@ -178,8 +178,8 @@ private sealed class HostingListener : IObserver<DiagnosticListener>, IObserver<
178178

179179
private readonly TaskCompletionSource<object> _hostTcs = new();
180180
private IDisposable? _disposable;
181-
private Action<object>? _configure;
182-
private Action<Exception?>? _entrypointCompleted;
181+
private readonly Action<object>? _configure;
182+
private readonly Action<Exception?>? _entrypointCompleted;
183183
private static readonly AsyncLocal<HostingListener> _currentListener = new();
184184

185185
public HostingListener(string[] args, MethodInfo entryPoint, TimeSpan waitTimeout, bool stopApplication, Action<object>? configure, Action<Exception?>? entrypointCompleted)

0 commit comments

Comments
 (0)