[Libwebsockets] Clean Reconnect not working

Deric Panet-Raymond dpraymond at satcomdirect.com
Sat Apr 11 20:11:10 CEST 2015

The problem is apparently when a TCP connection drops I'm not getting notified,  I tried turning on KeepALive but nothing seems to happen.  My application enters a death spiral where it spins at 100% CPU usage in the service_context loop.  The sequence is pull connection, app attempts to write data, the write is apparently successful even though the connection has been physically removed and then it goes back and spins in service_connection.

I'm kind of at a loss at this point.  My app is single threaded, I'm probably going to implement some sort of timer and if I dont receive a packet back from the server I'll tear down the connection and restart.

Sent from my LG Mobile

------ Original message------

From: Andy Green

Date: Sat, Apr 11, 2015 2:04 PM

To: Deric Panet-Raymond;libwebsockets at ml.libwebsockets.org;

Subject:Re: [Libwebsockets] Clean Reconnect not working

On 8 April 2015 22:59:06 GMT+08:00, Deric Panet-Raymond <dpraymond at satcomdirect.com> wrote:
>I am trying to design a reconnect sequence using libwebsockets for an
>application and I’m encountering an issue where it seems like the
>callbacks registered by the protocol aren’t being executed after a
>reconnect.  My current sequence has moved the connection to a function
>called open_connection where I create a libwebsocket context and
>perform the connect in a loop as the application will most likely start
>prior to the Network connection being live.  Our connection environment
>can be sporadic, hence the need for automatic connection and reconnect
>after disconnect.
>Once it’s connected everything appears to work well, it seems to
>survive one or two disconnects, I have a LWS_CALLBACK_CLOSED case which
>destorys the libwebsocket context and resets some state variables, then
>calls open_connection again.
>Can you think of something I might be missing that would cause the
>open_connection to fail after a couple of connect/disconnect cycles, is
>there a cleaner way to implement the reconnect?

Actually the test client heavily tests this... he gives each connection a small random 'lifetime' after which he closes and reconnects.

So I think it's probably okay in lws in general.

I think you need to turn up the debug loglevel and find out what the last thing happening on the last reconnect is.


>Deric Panet-Raymond
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20150411/db14fcea/attachment-0001.html>

More information about the Libwebsockets mailing list