http-server icon indicating copy to clipboard operation
http-server copied to clipboard

Memory leak ?

Open mingodad opened this issue 10 years ago • 1 comments

Hello !

Testing the simple.c on linux with httpress (https://bitbucket.org/yarosla/httpress/wiki/Home) the memory consumption only grows on each run, also if we try to use 100 or more concurrent connections the server die.

httpress -t 2 -n 100000 -c 40 -k http://127.0.0.1:5000/
*** Error in `./simple': malloc(): smallbin double linked list corrupted: 0x094a5a40 ***
Aborted (core dumped)

mingodad avatar Apr 01 '15 14:04 mingodad

Hi,

Sorry for delayed reply but I have been really busy recently. I suspect that the issue is caused by the fact that all responses are buffered into memory and at this moment there is no limit to the buffer. It should work as following:

void buffer_is_consumed(client * ptr) {
    while (!outgoing_buffer_is_full(client)) {
        write_response_to_client(client, data, sizeof(data));
    }
}

// buffer_is_consumed is a callback that is called for client whenever outgoing buffer has free space

This way we can keep the buffer memory limited (ie. 1MB default). Similiar to nodejs and their http server library and how their producer/consumer pattern works.

Regarding the memory corruption you mentioned might be related with buffering as well. Can you please run the simple app through "gdb" and post backtrace?

Thanks

mpapierski avatar Jun 06 '15 06:06 mpapierski