Skip to main content

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

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.

Back to the top