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

Commit d9237b3

Browse files
committed
Merge pull request #136 from Tragetaschen/shutdown-dispose-exception
Catch exceptions while disposing
2 parents 217f9ca + 6cd5744 commit d9237b3

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
@@ -8,6 +8,7 @@
88
using Microsoft.Framework.ConfigurationModel;
99
using Microsoft.Framework.DependencyInjection;
1010
using Microsoft.Framework.DependencyInjection.Fallback;
11+
using Microsoft.Framework.Logging;
1112
using Microsoft.Framework.Runtime;
1213

1314
namespace Microsoft.AspNet.Hosting
@@ -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 an exception", ex);
72+
}
6373
shutdownHandle.Set();
6474
});
6575

0 commit comments

Comments
 (0)