[Libwebsockets] Error when closing and reopening client.

Andy Green andy at warmcat.com
Tue Nov 15 19:00:18 CET 2016



On November 16, 2016 12:03:00 AM GMT+08:00, Stephen James <sajames1958 at gmail.com> wrote:
>I have implemented a client that will reconnect to the server on close.
>I have implemented close by returning -1 from the callback handler.
>
>Sometimes I see the following error: and then crash - I am assuming the
>fault lie in my code but was hoping for any insight.
>
>11/15/16 15:54:32.955: DBG 3C92: [websocket_callback_client:223]
>LWS_CALLBACK_CLIENT_CONNECTION_ERROR

Firstly, the client connect process is a bit unusual in that the call creates a new wsi and does callbacks on it before returning to the caller with the new wsi pointer, which may end up being NULL if the connection failed.

To straighten that out, you can point to the caller's storage for the new wsi in the client connect info struct.  This gets filled in before any callbacks, and before returning from the client connect api.

struct lws **pwsi;
	/**< if not NULL, store the new wsi here early in the connection
	 * process.  Although we return the new wsi, the call to create the
	 * client connection does progress the connection somewhat and may
	 * meet an error that will result in the connection being scrubbed and
	 * NULL returned.  While the wsi exists though, he may process a
	 * callback like CLIENT_CONNECTION_ERROR with his wsi: this gives the
	 * user callback a way to identify which wsi it is that faced the error
	 * even before the new wsi is returned and even if ultimately no wsi
	 * is returned.
	 */

>B8CA3A8A66F3-00003C85-582B2FB8-0056 :
>11/15/16 15:54:32.955: DBG 3C8E: [sLog:309] 1, no wsi found for sock fd
>12
>at pos -1, pt->fds_count=0

Secondly you should follow the code in the test client, which does auto-reconnect and connection rate limit properly, including taking care of the first issue correctly.

-Andy

>11/15/16 15:54:32.955: DBG 3C92: [QzWebSocketClient::ClientError:477]
>11/15/16 15:54:32.955: DBG 3C8E: [websocket_callback_client:223]
>LWS_CALLBACK_CLIENT_CONNECTION_ERROR
>B8CA3A8A66F3-00003C85-582B2FB8-0056 :
>11/15/16 15:54:32.955: APP 3C92: [OnError:405]
>11/15/16 15:54:32.955: DBG 3C8E: [QzWebSocketClient::ClientError:477]
>11/15/16 15:54:32.955: APP 3C8E: [OnError:405]
>11/15/16 15:54:32.955: DBG 3C8E: [NzWatsonClient::OnError:156]
>11/15/16 15:54:32.955: DBG 3C92: [NzWatsonClient::OnError:156]
>*** Error in `11/15/16 15:54:32.955: DBG 3C8E:
>[websocket_callback_client:289] Unhandled callback: 30
>Debug_x64/NzSpeechToText': double free or corruption (out): 0x11/15/16
>15:54:32.956: DBG 3C92: [websocket_callback_client:289] Unhandled
>callback:
>30
>11/15/16 15:54:32.956:*ERR*3C92: Aborted.
>
>11/15/16 15:54:32.956:*ERR*3C92: Aborted.
>00007FA4AA7D6C37 gsignal
>00007FA4AA7DA027 abort
>00007FA4AB4E0252 _realloc
>00007FA4AB4D96CE lws_close_free_wsi
>00007FA4AB4DB4D8 lws_service_fd_tsi
>00007FA4AB4E630A lws_plat_service_tsi
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org
>http://libwebsockets.org/mailman/listinfo/libwebsockets




More information about the Libwebsockets mailing list