[Libwebsockets] Hit assert at /home/bruce/libwebsockets/lib/output.c:112

Andy Green andy at warmcat.com
Fri Jun 12 02:33:14 CEST 2015

On 11 June 2015 03:43:12 GMT+08:00, Roger Light <roger at atchoo.org> wrote:
>Hi Bruce,
>If I'm remembering correctly, that's caused by you calling
>libwebsocket_write() when the library isn't ready. Try checking for
>!lws_send_pipe_choked(wsi) before you call libwebsocket_write().

It means something more specific somehow your code is trying to write new data outside of the WRITEABLE callback.

Because lws is nonblocking, he cannot make a firm promise about how much of your buffer the kernel will accept to send at any given time.

If you ask to send 4KB but the kernel only accepted 3KB, we cannot block and spin until he accepts the other 1KB; it's open-ended if that would even happen or how long it would take according to per-connection conditions.  So to cover this case, lws will malloc up a per-connection buffer for this "partial send" and ban any callbacks with WRITEABLE from reaching user code until the buffer is drained.  (Because if this happens once, it's likely to happen again, lws also lets the per-connection buffer hang around, remalloc-ing it as necessary if it needs to get bigger).

Because you should only send from WRITEABLE callback, that should hide the fact it's buffered and draining, without any blocking.

But if you (or the library... but that would be a bug...) tries to write something new while the connection is in this "draining the partial buffer state", it will blow this assertion, because the new write is trying to crap up the pending one.

lws_pipe_choked(wsi) is a way to check if sending would block.  You can use it to stuff the pipe in your WRITEABLE callback up to the point it would block at the next write, for throughput reasons.  It's relatively inexpensive timewise because the writes are guaranteed to not block even if you are doing several (the last one may not block but get you into a partial send state.... but that is handled by the library as described).


>On Wed, Jun 10, 2015 at 7:20 PM, Bruce Perens <andy.green at linaro.org>
>> Hi,
>> What does it mean when I hit this assert?
>>     Thanks
>>     Bruce
>> 107 if (wsi->truncated_send_len && (buf < wsi->truncated_send_malloc
>> 108 buf > (wsi->truncated_send_malloc +
>> 109 wsi->truncated_send_len +
>> 110 wsi->truncated_send_offset))) {
>> 111 lwsl_err("****** %x Sending new, pending truncated ...\n", wsi);
>> 112 assert(0);
>> 113 }
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> http://ml.libwebsockets.org/mailman/listinfo/libwebsockets
>Libwebsockets mailing list
>Libwebsockets at ml.libwebsockets.org

More information about the Libwebsockets mailing list