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

ServerFactory.Start does not cleanup properly if exception after first engine.CreateServer #102

Closed
smbecker opened this issue May 20, 2015 · 0 comments

Comments

@smbecker
Copy link

If multiple addresses are being used in ServerFactory and an exception is thrown in engine.CreateServer, then the proceeding disposables are not cleaned up properly. Consider changing the method implementation to something similar to:

public IDisposable Start(IServerInformation serverInformation, Func<IFeatureCollection, Task> application)
{
    var disposables = new List<IDisposable>();
    var dispose = new Disposable(() =>
    {
        foreach (var disposable in disposables)
        {
            disposable.Dispose();
        }
    });
    var information = (ServerInformation)serverInformation;
    var engine = new KestrelEngine(_libraryManager);
    engine.Start(1);
    try
    {
        foreach (var address in information.Addresses)
        {
            disposables.Add(engine.CreateServer(
                address.Scheme,
                address.Host,
                address.Port,
                async frame =>
                {
                    var request = new ServerRequest(frame);
                    await application.Invoke(request.Features);
                }));
        }
        disposables.Add(engine);
        return dispose;
    }
    catch (Exception)
    {
        dispose.Dispose();
        throw;
    }
}
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants