Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [paho-dev] Help troubleshooting python paho.mqtt.client loop returns 1

Hi again all,

I found the problem.

I had been calling loop with a timeout value of 1000 (since I
accidentally used ms instead of s), but the timeout for the connection
was less than that. I was kind of expecting that the loop-call would
be sending the required keepalives anyway. But it doesn't do that,
hence the server didn't get a keepalive in time and thus the
connection got torn down from the server end.

So I propose the following changes:

The line:

if len(command) == 0:
                    return 1

should be changed into:

if len(command) == 0:
                    return MQTT_ERR_CONN_LOST

Also, there are many places in client.py where 1 is used as a generic
error code. Should they be reviewed and changed to more appropriate
codes, or even MQTT_ERR_UNKNOWN?

and possibly something like this added to the beginning of the loop-method:

if timeout >= self._keepalive:
            raise ValueError('Invalid timeout. Timeout must not be
greater or equal to keepalive interval. It should be significantly
smaller.')

Thank you for your product, and have a nice day all of  you! :-)

/Anders

On Sun, Aug 2, 2015 at 10:50 PM, anders musikka
<anders.musikka@xxxxxxxxx> wrote:
> Hello Paho-devs,
>
> This is my first post on this list.
>
> I'm trying to use the paho.mqtt client in a project on a raspberry pi.
> I installed using pip:
>
> pip install paho-mqtt
>
> The problem I'm having is that intermittently, the paho.mqtt.client
> "loop"-function returns 1.
>
> Looking through the source, I see that this error code is defined as
> MQTT_ERR_NOMEM. By sprinkling print statements in the source, I was
> able to narrow it down to line 1420 in client.py:
>
>                 if len(command) == 0:
>                     return 1
>
> This is in the function _packet_read in the client class. This
> executes, and the 1 is propagated all the way out to the return value
> of the loop function.
>
> The case when len(command)==0 seems like it should only occur if the
> socket has been shutdown by the other end.
>
> It seems to me to be a bug that 1 is returned here, since there's no
> indication that memory would be out.
>
> But the bigger question is why this happens in the first place. I'm
> using the mosquitto server, and I've tried using mosquitto_sub to
> subscribe to messages, and that seems to work "forever" without losing
> connection, crashing or hanging or anything.
>
> I'll continue my investigation, but I thought I'd ask on this list if
> anyone has seen this before or has any clever approaches to finding
> the cause of my problem.
>
> The problem is repeatable, after starting my application it only runs
> for approximately 1 minute, maybe 20-30 messages, before this happens.
>
> Ofcourse I could just handle this error, reconnect, and continue, but
> I'd like to get to the bottom of the issue :-).
>
>
> /Anders


Back to the top