File tree Expand file tree Collapse file tree 1 file changed +13
-3
lines changed
src/Hosting/Hosting/src/Internal Expand file tree Collapse file tree 1 file changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -78,11 +78,21 @@ private void OnApplicationStopping()
7878
7979 private void OnProcessExit ( object sender , EventArgs e )
8080 {
81- ApplicationLifetime . StopApplication ( ) ;
82- if ( ! _shutdownBlock . WaitOne ( HostOptions . ShutdownTimeout ) )
81+ try
82+ {
83+ ApplicationLifetime . StopApplication ( ) ;
84+ if ( ! _shutdownBlock . WaitOne ( HostOptions . ShutdownTimeout ) )
85+ {
86+ Logger . LogInformation ( "Waiting for the host to be disposed. Ensure all 'IHost' instances are wrapped in 'using' blocks." ) ;
87+ }
88+ }
89+ // When hosting with IIS in-process, we detach the Console handle on main thread exit.
90+ // Console.WriteLine may throw here as we are logging to console on ProcessExit.
91+ // We catch and ignore all exceptions here. Do not log to Console in thie exception handler.
92+ catch ( Exception )
8393 {
84- Logger . LogInformation ( "Waiting for the host to be disposed. Ensure all 'IHost' instances are wrapped in 'using' blocks." ) ;
8594 }
95+
8696 _shutdownBlock . WaitOne ( ) ;
8797 // On Linux if the shutdown is triggered by SIGTERM then that's signaled with the 143 exit code.
8898 // Suppress that since we shut down gracefully. https://github.com/aspnet/AspNetCore/issues/6526
You can’t perform that action at this time.
0 commit comments