Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [mosquitto-dev] runaway loop with client lib and SSL

Hi Dave,

Sorry for the delay in replying, I took some time off from computers
around Christmas and the New Year.

You've posted a sound analysis from what I can see. want_write never
gets cleared and that's a definite mistake. Thanks for pointing it
out. I've just committed and push a fix for this to the 1.4 branch.



On Wed, Dec 17, 2014 at 12:42 PM, Dave Sellars <dave.sellars@xxxxxxxxx> wrote:
> Hello
> I'm using the mosquitto version 1.2.1 (but I have also found the same issue
> in 1.3.5), using the client library to implement a secure connection to a
> broker (using SSL/TLS) and seeing a strange issue, where the mosquitto
> 'loop' consumes all available cycles on one core.
> I am using the threaded interface, and have also tried calling
> mosquittop_loop() in my own loop/thread, and I see the same thing.
> Essentially, I try to send a "large" message (around 80K bytes) and after
> this, the loop just spins. As far as I can see from my debugging, the reason
> is that at some point, SSL_write() returns SSL_ERROR_WANT_WRITE and the flag
> mosq->want_write is set to 'true'. From then on, the code in
> mosquitto_loop() checks whether the 'want_write' flag is set, and if so adds
> the FD to the writefds set before calling select(). The problem seems to be
> that the 'want_write' flag is never cleared (anywhere in the source tree, as
> far as I can see!). So, after this, the socket FD is *always* added to the
> 'writefds' set, and because it is almost always writeable (in my very low
> traffic application), select() always returns immediately, and hence
> mosquitto_loop() always calls _mosquitto_packet_write(), which has nothing
> to write, so returns immediately. This just goes on and on forever, causing
> the loop's thread to run away with the CPU.
> Before I send my "large" message, the 'want_write' flag is false, and the
> select() loop behaves as expected, timing out most of the time, until there
> is some traffic on the connection. After the large message has gone through,
> and the want_write flag is set, it loops as fast as it can... Whilst it
> isn't an unbreakable loop, and messages in and out do get handled, it seems
> wrong that 'want_write' is never cleared.
> I find it odd that no-one else has encountered this, and I understand that
> the OpenSSL API is quite a beast to get to grips with, but it seems to me
> that the want_write flag should be cleared just before calling
> mosquitto_loop_write(), in mosquitto_loop().
> Does anyone understand the OpenSSL interface well enough to tell whether I'm
> right or wrong?
> thanks
>   Dave.
> _______________________________________________
> mosquitto-dev mailing list
> mosquitto-dev@xxxxxxxxxxx
> To change your delivery options, retrieve your password, or unsubscribe from
> this list, visit

Back to the top