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

Catch exceptions while disposing #136

Merged
merged 1 commit into from
Jan 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/Microsoft.AspNet.Hosting/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Framework.ConfigurationModel;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.DependencyInjection.Fallback;
using Microsoft.Framework.Logging;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sort the usings.

using Microsoft.Framework.Runtime;

namespace Microsoft.AspNet.Hosting
Expand Down Expand Up @@ -52,14 +53,23 @@ public void Main(string[] args)
};

var engine = services.GetRequiredService<IHostingEngine>();
var loggerFactory = services.GetRequiredService<ILoggerFactory>();
var appShutdownService = _serviceProvider.GetRequiredService<IApplicationShutdown>();
var shutdownHandle = new ManualResetEvent(false);

var serverShutdown = engine.Start(context);

appShutdownService.ShutdownRequested.Register(() =>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispose should never throw. We should fix Kestrel

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we should fix Kestrel so it doesn't throw. That said, since Hosting will be interacting with 3rd party components here we should make it more defensive, especially when the consequence is a hang.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah what @Tratcher said. Need to fix both sides.

{
serverShutdown.Dispose();
try
{
serverShutdown.Dispose();
}
catch (Exception ex)
{
var logger = loggerFactory.Create<Program>();
logger.WriteError("TODO: Dispose threw an exception", ex);
}
shutdownHandle.Set();
});

Expand Down