[Libwebsockets] Problem sending more than 3263 bytes on ws

pierre30 at gmail.com pierre30 at gmail.com
Thu Jun 28 14:53:47 CEST 2018

Thank you very much for the answer. I tried your example (without 
modification) but it's the same problem. See below.

Le 28-06-18 à 05:05, Andy Green a écrit :
> On 06/27/2018 11:36 PM, pierre30 at gmail.com wrote:
>> Hello,
>> I have a problem when sending more than 3263 bytes on websocket using 
>> lws_write() function. The problem appears with firefox and 
>> libwebsocket version 3.0.I had no problem with version 2.0 whatever 
>> the browser I used. It’s still good with Edge and version 3.0.
>> When I try to send 3264 bytes, I receive 3421 bytes (+ 157 bytes) in 
>> the Javascript on Firefox. Idem when I try to send more bytes, the 
>> Javascript receive extra bytes in multiples of 157. If I try to send 
>> 41990 bytes, I receive 42304 bytes (+ 2*157 bytes).
> Are these "extra bytes" recognizable as being related to what should 
> have been sent?  Like the last 157 bytes repeated, etc?

In fact the extra bytes are bytes from next calls to lws_write(). If I 
do only one call to lws_write() with a big packet, ws.onmessage is not 
called on the client javascript.
NB: The number of bytes from which the problem occurs depends on the 
content (how it's compressed by permessage-deflate?). If I try to send a 
repeatable pattern I can send many more bytes without problem.

>> On the libwebsocket side here are the following notice messages (no 
>> notice when connected with Edge):
>> [2018/06/27 16:26:41,519] Send WS: size = 3264
>> [2018/06/27 16:26:41,519] NOTICE: write drain len 1019 (wp 0x1) 
>> SETTING tx_draining_ext
> Hmm you seem to be using permessage-deflate compression extension.
Yes I use permessage-deflate and if I don't use it everything is fine 
(correct number of bytes received and no NOTICE on the server).

> You can do that but you have some extra constraints to be aware of.
What constraints ?

>> [2018/06/27 16:26:41,519] lws_write() return: 3264
>> [2018/06/27 16:26:41,549] NOTICE: rops_write_role_protocol_ws: 
>> CLEARING tx_draining_ext
>> [2018/06/27 16:26:41,549] NOTICE: FORCED draining wp to 0x02 (stashed 
>> 0x01, incoming 0x01)
>> [2018/06/27 16:24:42,460] Send WS: size = 41990
>> [2018/06/27 16:24:42,465] NOTICE: write drain len 1019 (wp 0x1) 
>> SETTING tx_draining_ext
>> [2018/06/27 16:24:42,465] lwswrite() return: 41990
>> [2018/06/27 16:24:42,498] NOTICE: rops_write_role_protocol_ws: 
>> CLEARING tx_draining_ext
>> [2018/06/27 16:24:42,498] NOTICE: FORCED draining wp to 0x02 (stashed 
>> 0x01, incoming 0x01)
>> [2018/06/27 16:24:42,498] NOTICE: write drain len 1024 (wp 0x2) 
>> SETTING tx_draining_ext
>> [2018/06/27 16:24:42,545] NOTICE: rops_write_role_protocol_ws: 
>> CLEARING tx_draining_ext
> ...
>> I don’t understand what the notice means and what I can do in 
> They shouldn't be NOTICE but more like DEBUG or EXT, they seem to have 
> been left like that accidentally from debugging.  They are just 
> informing about progress of sending stuff.
>> libwebsocket to have something working on Firefox?
> My guess is disabling the extension will make it "go away" but it's 
> not really fixing anything.
You're right.

> It's surprising since we run autobahn now on travis commits.
> Could you maybe take a look at
> https://libwebsockets.org/git/libwebsockets/tree/minimal-examples/ws-server/minimal-ws-server-pmd-bulk 
> and see if that has the same problem when aligned to what your code is 
> doing (or align your code to what that's doing...)
I have trouble to make the minimal-ws-server-pmd-bulk example working 
without modification.

With Edge it seems to work. On the big texarea it is written "Received: 
133700 bytes" and on the console : "Received ws message len 133700". No 
notice on the server side.
NB: It is not related to my problem but for information if I try to send 
something with the send button, i get this error in Edge console: 
SCRIPT12030: SCRIPT12030: WebSocket Error: Network Error 12030, La 
connexion avec le serveur a été interrompue anormalement

With Firefox and with Chrome I dont get anything in the big textarea and 
the console remains empty.
It seems that the callback ws.onmessage is not called but on the server 
side it is sending something I have the same kind of NOTICE messages as 
with my server.
[2018/06/28 13:49:27:7268] NOTICE: write drain len 1019 (wp 0x41) 
SETTING tx_draining_ext
[2018/06/28 13:49:27:7268] USER: LWS_CALLBACK_SERVER_WRITEABLE: wrote 1024
[2018/06/28 13:49:27:7269] NOTICE: rops_write_role_protocol_ws: CLEARING 
[2018/06/28 13:49:27:7270] NOTICE: FORCED draining wp to 0x42 (stashed 
0x41, incoming 0x42)
[2018/06/28 13:49:27:7272] NOTICE: write drain len 1024 (wp 0x42) 
SETTING tx_draining_ext
[2018/06/28 13:49:27:7273] USER: LWS_CALLBACK_SERVER_WRITEABLE: wrote 1024
[2018/06/28 13:49:27:7313] NOTICE: rops_write_role_protocol_ws: CLEARING 
[2018/06/28 13:49:27:7313] NOTICE: FORCED draining wp to 0x42 (stashed 
0x42, incoming 0x42)
[2018/06/28 13:49:27:7316] NOTICE: write drain len 1024 (wp 0x42) 
SETTING tx_draining_ext
[2018/06/28 13:49:27:7317] USER: LWS_CALLBACK_SERVER_WRITEABLE: wrote 1024

The problem seems to be the same with my server and your example server...
If I reduce the size of the message REPEAT_STRING_LEN = 500, no problem.
Here also if I disable the permessage-deflate extension I get the 133700 
bytes in the textarea and the console. The problem seems to be linked to 
permessage-deflate. Maybe Edge is not using permessage-deflate?

Is it possible that permessage-deflate sends a wrong packet size bigger 
than the actual size?

I tried version libwebsockets 3.0.0 v2.0.0-985-gc708bda0.

Could you reproduce it or does it works well on your computer?


> -Andy
>> Thanks,
>> Pierre.
>> _______________________________________________
>> Libwebsockets mailing list
>> Libwebsockets at ml.libwebsockets.org
>> https://libwebsockets.org/mailman/listinfo/libwebsockets

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://libwebsockets.org/pipermail/libwebsockets/attachments/20180628/1cf3af95/attachment-0002.html>

More information about the Libwebsockets mailing list