Re: [Cppcms-users] Simple long polling application has memory leaks (sockets left in CLOSE_WAIT stat
Brought to you by:
artyom-beilis
From: Cody S. <cod...@gu...> - 2016-01-15 16:54:57
|
Artyom Beilis <artyom.beilis@...> writes: > > The problem is that detecting that the connection isn't alive isn't reliable. > > Especially when working via webserver and fastcgi/scgi. > > You always need to have timeouts on connections especially long- polling > ones. > > For example if you know that client resubmits request every 10 seconds > (also I'd suggest > to increase it) put your own 10 seconds timeout as well as you know that the > client will disconnect so why to keep one alive. > > Always manage timeouts on asynchronous requests. > > Artyo > > > > > The problem arises in an ajax function called "listen()", which makes an > > ajax POST request to the server and waits until the server has responded > > or 10 seconds have passed, at which point it will fire up another "long- > > polling" request. However, each of these requests remains open in the > > case that they time out, and then the lighttpd server refuses any more > > connections after too many requests have been issued. I'm not sure what > > I'm doing wrong with my long-polling approach, but for some reason, > > these sockets are not getting closed and I've been unable to determine > > why after 2 days of investigating. > > > > Thanks, that seems to really address the heart of the issue. Just for clarification: async_on_peer_reset isn't automagically tracking the client timeout and performing some cleanup? I think that was the fundamental assumption that I had that went wrong. I expected that in this code: void listen() { booster::shared_ptr<cppcms::http::context> context = release_context(); waiters_.insert(context); context->async_on_peer_reset( std::bind( &chat::remove_context, this, context)); } the callback passed into async_on_peer_reset would get called on client timeout. The documentation here: http://cppcms.com/cppcms_ref/latest/classcppcms_1_1http_1_1context.html# a0f6fe53deabd90fee0ced81a8df6404e seems to indicate that that is a valid expectation. P.S. Sorry for blowing up the thread above with repeat submissions; I thought gmane may have dropped my post. I'll be more patient this time ;) Also, thanks for the framework and all your hard work; I'm having a great time jumping into web dev. and C++ with your tool! |