jgauffin / Griffin.WebServer

A web server built on top of Griffin.Framework
107 stars 42 forks source link

It's not possible to run multiple HTTP servers in a single process / static buffer issue #7

Closed morpheusxx closed 11 years ago

morpheusxx commented 11 years ago

I need to run multiple HTTP server instances within a single process to support multiple IP addresses and multiple sites.

In principle I'm trying to:

        var server_IPv4 = new HttpServer(moduleManager);
        server_IPv4.Start(IPAddress.Any, 0);

        var server_IPv6 = new HttpServer(moduleManager);
        server_IPv6.Start(IPAddress.IPv6Any, 0);

The 2nd call does fail when the HttpMessageBuilder pop slices from "_stack" which is defined as:

    private static readonly IBufferSliceStack _stack = new BufferSliceStack(100, 65535);

So after the static 100 buffers are used for first server, the 2nd one will fail in Pop method with:

    public IBufferSlice Pop()
    {
        PooledBufferSlice slice;
        if (_slices.TryPop(out slice))
            return slice;

        throw new InvalidOperationException(string.Format("All {0} has been given out.", _numberOfBuffers));
    }

Simply removing "static" from buffer definition causes an OutOfMemoryException, as the total number of buffer would be created for each "Pop".

Is this WebServer intended to run only as one instance per process? If not, this is a bug and I really would like to see it fixed soon :-)

jgauffin commented 11 years ago

The change was in Griffin.Networking. the HttpMessageFactory now has a constructor which takes a bufferslicestack. So when you create the WebServer use the constructor which takes a configuiration DTO.