Skip to content
This repository was archived by the owner on Dec 19, 2018. It is now read-only.

Commit 44d2b4d

Browse files
author
Kai Ruhnau
committed
Catch exceptions while disposing
1 parent 217f9ca commit 44d2b4d

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Microsoft.AspNet.Hosting/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using Microsoft.Framework.DependencyInjection;
1010
using Microsoft.Framework.DependencyInjection.Fallback;
1111
using Microsoft.Framework.Runtime;
12+
using Microsoft.Framework.Logging;
1213

1314
namespace Microsoft.AspNet.Hosting
1415
{
@@ -52,14 +53,23 @@ public void Main(string[] args)
5253
};
5354

5455
var engine = services.GetRequiredService<IHostingEngine>();
56+
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
5557
var appShutdownService = _serviceProvider.GetRequiredService<IApplicationShutdown>();
5658
var shutdownHandle = new ManualResetEvent(false);
5759

5860
var serverShutdown = engine.Start(context);
5961

6062
appShutdownService.ShutdownRequested.Register(() =>
6163
{
62-
serverShutdown.Dispose();
64+
try
65+
{
66+
serverShutdown.Dispose();
67+
}
68+
catch (Exception ex)
69+
{
70+
var logger = loggerFactory.Create<Program>();
71+
logger.WriteError("TODO: Dispose threw exception:\n{0}\n{1}", ex.Message, ex.StackTrace);
72+
}
6373
shutdownHandle.Set();
6474
});
6575

0 commit comments

Comments
 (0)