[Libwebsockets] client never connects if lws_service timeout is zero

Andy Green andy at warmcat.com
Sat Oct 8 02:07:27 CEST 2016


On Fri, 2016-10-07 at 18:43 +0200, Denis Osvald wrote:
> On 2016-10-07 18:19, Rob Agar wrote:
> > 
> > Hi all
> 
> Hi,
> 
> > 
> > 
> > I've just come across an odd problem when updating to 2.1.  If I
> > pass
> > zero as the timeout to /lws_service/, my client never connects to
> > the
> > server, but if I set it to 1ms, it works as it did before when it
> > used 1.7
> > 
> > I'll try and replicate with a minimal test case & raise an issue if
> > I
> > can, but in the mean time has anyone else found this behaviour? Or
> > am I
> > forgetting to do something?
> > 
> > cheers
> > 
> > Rob 
> > 
> 
> I think the bug is here in lws-plat-unix.c :
> 
> lws_plat_service_tsi( ... )
> 
> 	timeout_ms = lws_service_adjust_timeout(context, timeout_ms,
> tsi);
> 	/*
> 	 * is there anybody with pending stuff that needs service
> forcing?
> 	 */
> ----->	if (!timeout_ms) {
> 		/* -1 timeout means just do forced service */
> 		lws_plat_service_tsi(context, -1, pt->tid);
> 		/* still somebody left who wants forced service? */
> 		if (!lws_service_adjust_timeout(context, 1, pt->tid)) {
> 			/* yes... come back again later */
> 			lwsl_debug("%s: done again\n", __func__);
> 		}
> 		return 0;
> 	}
> 
> 	n = poll(pt->fds, pt->fds_count, timeout_ms);
> 
> 
> After call to adjust_timeout, timeout_ms can be 0 for 2 reasons:
> - we were asked to poll with timeout 0 = non-blocking
> - don't poll but only force service old input data (because new
> timeout
> returned by adjust_timeout was 0)
> 
> The code probably shouldn't overwrite timeout_ms, but use both old
> and
> new one to make the correct decision.

That is true, but it's also true that entering the poll() with 0
timeout means busywaiting.

In the mailing list archives somewhere is at least one guy asking "why
is my cpu at 100%" and the answer is he was just spinning with no idle
time since he told poll() to exit immediately.

What's the legit use-case for asking to enter a poll wait with 0
timeout from the user code?  If there is one then maybe something to
do, but eg libuv loop ignores it, external poll waits externally...

-Andy

> Andy, feel free to correct me.
> 
> 
> > 
> > 
> > 
> > 
> > _______________________________________________
> > Libwebsockets mailing list
> > Libwebsockets at ml.libwebsockets.org
> > http://libwebsockets.org/mailman/listinfo/libwebsockets
> > 



More information about the Libwebsockets mailing list