[Libwebsockets] libwebsocket message loop thread take 100% of the CPU

Andy Green andy at warmcat.com
Mon Aug 24 17:06:23 CEST 2020

On 8/24/20 4:00 PM, Peiffer Eric wrote:
> Hi,
> I have an application that open thousand of clients websocket and use 
> the default event loop poll().
> The thread that run the event loop execute only the following line of code:
> while (n >= 0 && !interrupt) {
>        n = lws_service(context, 0);
> }
> This work well, but sometimes this thread  take 100% of the CPU and no 
> more callback is called.
> Has anyone ever had this behaviour?

If it's spinning somewhere, you are going to have to find out where (eg, 
attach with gdb -p and ctrl-c step it), or provide a way to reproduce it.

Asking "does it normally drop dead and spin somewhere?", the answer is "no".

But lws is a library, a coproduction between its code and your code, if 
in your user code you do things like call lws apis from other threads 
illegally you can trash its internal state pretty quickly.


> Regards,
> Eric Peiffer
> .
> _______________________________________________
> Libwebsockets mailing list
> Libwebsockets at ml.libwebsockets.org
> https://libwebsockets.org/mailman/listinfo/libwebsockets

More information about the Libwebsockets mailing list