[Libwebsockets] How to properly handle LWS_CALLBACK_CLIENT_CONNECTION_ERROR?

Andy Green andy at warmcat.com
Thu Jun 28 04:05:52 CEST 2018



On 06/27/2018 10:24 PM, Alfred Sawaya wrote:
> Hello Duane,
> 
> A memory leak has been corrected in the v3.0 branch. It happens exactly 
> in your case (when a websocket fails to upgrade), can you try this version ?
> https://github.com/warmcat/libwebsockets/commit/3f7ffeddac34e85c5c000c687dbdbd204e74b376

I think that leak was introduced between 2.4 and 3.0, and corrected in 
v3.0-stable.  So it's probably not his issue.

The leak is likely fixed anyway in v3.0 though.  So please try it.

If not, use valgrind and provide information about exactly what is leaking.

About the other things, it doesn't matter about the client info struct 
lifetime, everything in it is copied out by the call.

It sounds like OP has this working, but depending on who creates the 
client connection, there are different ways to keep it nailed up.  If a 
protocol basically owns the client connection, a nice way is to build 
the retries into the protocol

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c#n81-100

https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-client/minimal-ws-client-pmd-bulk/protocol_lws_minimal_pmd_bulk.c#n264-270

using the per-vhost protocol timer.

-Andy



More information about the Libwebsockets mailing list