[Libwebsockets] Odd "ERR: Ran out of header data space" error?

Andy Green andy at warmcat.com
Fri Jun 19 20:10:48 CEST 2020

On 6/19/20 6:58 PM, Bent Bisballe Nyeng wrote:
> Thank you very much for you reply :-)
> On 06/19/20 18:01, andy at warmcat.com wrote:
>> On June 19, 2020 3:20:47 PM UTC, Bent Bisballe Nyeng <deva at aasimon.org> wrote:
>>> Hi List
>>> I am making a server based on libwebsockets which serves textual
>>> updates
>>> to all connected user based on user input, akin to the drawing example
>>> application; ie. everybody gets notificed about all changes.
>>> My application uses a textual protocol and these messages can sometimes
>>> be ~16kb and above.
>>> The system on which I am developing is based on libwebsocket 2.1 and
>>> everything seem to be working fine.
>>> Recently, however, I deployed the service on a debian server for
>>> borader
>>> use, which has libwebsocket 2.0 installed and then I started seeing the
>> 2.0... it's very old.
> Yes I thought so as well - but this is for some reason the version that
> Debian is currently shipping... ;)


>>> error: "ERR: Ran out of header data space" a lot.
>>> I traced it to the max_http_header_data parameter which in my
>>> application was unset (ie. 0) and increasing it to 16kb seemed to
>>> somewhat mitigate the issue.
>>> I do not, however, understand why I am seeing that error in the first
>>> place, shouldn't that parameter only affect http connections?
>> I assume it's websockets... all ws connections start off as http.  And the server catches and stores any headers it understands, but it is not in control of, eg, how big the cookies are a browser will send it.  At some point I set the default size to 4KB it'd make sense if before v2.1 it was smaller.
> So what you are saying is that it might be the size of my cookies which
> is causing my problem and not as I initially thought the payload size of
> my protocol ...
> It does make sense since the number of cookies are growing linearly with
> the size of my payload.

It's the size of the header that is being sent from the client, that 
includes whatever cookies you have.  Since we discard headers we don't 
understand, usually the only big thing taking up space in there is 
cookies (whose header we do understand and capture the data).

> Are there any limitations to how much data can be transmitted in one
> lws_write call to a client?

Basically we do not control how much of what you want to send the OS 
will accept on the connection, it will literally 'pick a number' and if 
you have more, it will just leave it unsent.

For a long time (I am not sure if in v2.0) lws will notice it and copy 
it on the heap, and send it later in the background, concealing 
WRITEABLE until it's all gone.  So basically it will deal with this 
situation, but because it's relatively expensive in time and heap to do 
that, you generally want to avoid it... the times the kernel surprises 
you lws will conceal it, but you only want to be giving it chunks that 
it can immediately consume, generally.  That number is "a few MTU", it 
depends on the system and connection, a couple of KB is usually OK.

You can send that and ask for another writeable callback if more to send 
until you sent everything.  For ws, there is a helper to help you 
calculate the flags to give lws_write when producing these message fragments



>>> I am also not sure why I am seeing the error only on the debian server
>>> and not on my developent PC. Is this perhaps really a bug in 2.0 which
>>> has been fixed in 2.1?
>> This is all literally many years old.  We're on v4.0 now.
>>> Any advice on the matter will be very much appreciated :-)
>> It's better to build later stuff yourself.  Later lws supports cpack, you can create a .deb actually.
> I will try to reduce the number fo cookies and see if that fixes the
> issue. If it persists I will try to compile lws myself :-)
> Thank you for your help - and thank you for this great library :-)
> Kind regards
> Bent Bisballe Nyeng
>> -Andy
>>> Kind regards
>>> Bent Bisballe Nyeng
>>> _______________________________________________
>>> Libwebsockets mailing list
>>> Libwebsockets at ml.libwebsockets.org
>>> https://libwebsockets.org/mailman/listinfo/libwebsockets
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list