Skip to content
Prev Previous commit
Next Next commit
Adds env var options for setting timeout
  • Loading branch information
maryamariyan committed Nov 16, 2021
commit 5c4a8c9064ec394324543c79c53e8d56b9e1e2e6
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,25 @@ internal sealed class HostFactoryResolver
public const string BuildWebHost = nameof(BuildWebHost);
public const string CreateWebHostBuilder = nameof(CreateWebHostBuilder);
public const string CreateHostBuilder = nameof(CreateHostBuilder);
private const string TimeoutEnvironmentKey = "DOTNET_HOST_FACTORY_RESOLVER_DEFAULT_TIMEOUT_IN_SECONDS";

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

private static TimeSpan SetupDefaultTimout()
{
if (Debugger.IsAttached)
{
return Timeout.InfiniteTimeSpan;
}

if (uint.TryParse(Environment.GetEnvironmentVariable(TimeoutEnvironmentKey), out uint timeoutInSeconds))
{
return TimeSpan.FromSeconds((int)timeoutInSeconds);
}

return TimeSpan.FromSeconds(30);
}

public static Func<string[], TWebHost>? ResolveWebHostFactory<TWebHost>(Assembly assembly)
{
Expand Down