Skip to content

Commit

Permalink
Do not timeout HostingListener when debugging
Browse files Browse the repository at this point in the history
Do not timeout waiting for the host to start when running with
the debugger attached.

Addresses dotnet/aspnetcore#33886.
  • Loading branch information
martincostello committed Jun 27, 2021
1 parent 02f70d0 commit cc02874
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal sealed class HostFactoryResolver
public const string CreateHostBuilder = nameof(CreateHostBuilder);

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

public static Func<string[], TWebHost>? ResolveWebHostFactory<TWebHost>(Assembly assembly)
{
Expand All @@ -44,10 +44,10 @@ internal sealed class HostFactoryResolver
// 3. Give the caller a chance to execute logic to mutate the IHostBuilder
// 4. Resolve the instance of the applications's IHost
// 5. Allow the caller to determine if the entry point has completed
public static Func<string[], object>? ResolveHostFactory(Assembly assembly,
TimeSpan? waitTimeout = null,
bool stopApplication = true,
Action<object>? configureHostBuilder = null,
public static Func<string[], object>? ResolveHostFactory(Assembly assembly,
TimeSpan? waitTimeout = null,
bool stopApplication = true,
Action<object>? configureHostBuilder = null,
Action<Exception?>? entrypointCompleted = null)
{
if (assembly.EntryPoint is null)
Expand All @@ -64,7 +64,7 @@ internal sealed class HostFactoryResolver
{
return null;
}

// We're using a version >= 6 so the events can fire. If they don't fire
// then it's because the application isn't using the hosting APIs
}
Expand Down Expand Up @@ -178,8 +178,8 @@ private sealed class HostingListener : IObserver<DiagnosticListener>, IObserver<

private readonly TaskCompletionSource<object> _hostTcs = new();
private IDisposable? _disposable;
private Action<object>? _configure;
private Action<Exception?>? _entrypointCompleted;
private readonly Action<object>? _configure;
private readonly Action<Exception?>? _entrypointCompleted;
private static readonly AsyncLocal<HostingListener> _currentListener = new();

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

0 comments on commit cc02874

Please sign in to comment.