[Libwebsockets] How to drop sessions which don't request nothing
"Andy Green (林安廸)"
andy at warmcat.com
Sat Feb 15 07:38:26 CET 2014
On 30/01/14 11:58, the mail apparently from Alexandre Erwin Ittner included:
> Hi folks,
> Is there any established way to disconnect TCP sessions which connect to
> libwebsocket and sit idle, never starting an HTTP request nor sending any
> data, but still holding up a file descriptor, making poll queue longer,
> and, maybe, being kept up by TCP keep-alive?
> To get into this situation, fire up a telnet to the address/port of a
> libwebsockets-test-server and do nothing. For comparison, do the same to
> an Apache/nginx webserver -- it will drop the connection after a while,
> freeing up the resources.
I see... no, lws doesn't do anything about that at the moment.
It's accepted the connection then but no further activity is coming...
> Currently, I plan to handle this in my application by adding the file
> descriptor to a pending list once it is received in callback
> LWS_CALLBACK_FILTER_NETWORK_CONNECTION and removing it once it performs
> some request or gets removed by LWS_CALLBACK_DEL_POLL_FD (I'm using an
> external poll loop). From time to time, my application will scan the list
> and inject a fake POLLERR flag in the "revents" field before passing it
> to LWS, so the library can close and release any associated resource.
> Since my application handles timeouts after the connection reaches
> LWS_CALLBACK_ESTABLISHED, no special procedures are needed after this
> I also tried using the function libwebsocket_set_timeout -- setting a
> timeout to 10s in LWS_CALLBACK_FILTER_NETWORK_CONNECTION and setting it
> back to zero in LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, but I think I
> misunderstood the mechanism -- it only resulted in a segfault with a
> possible stack corruption which prevents GDB from getting to the failure
> point inside libwebsocket_service_fd().
I think the issue is you put the timeout on the listing wsi not the
accepted one ^^
I implemented this timeout here
please give it a go.
> My questions:
> - Is there a better way to do this with LWS infrastructure? Is this the
> idea behind libwebsocket_set_timeout ?
> - If not, is there any interest from the LWS user community in a patch
> to handle this situation inside the library? I can change my approach
> and write it.
> Thanks in advance,
More information about the Libwebsockets