Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LWT not sent on exceeded timeout #1143

Closed
salcedo opened this issue Feb 3, 2019 · 5 comments
Closed

LWT not sent on exceeded timeout #1143

salcedo opened this issue Feb 3, 2019 · 5 comments
Milestone

Comments

@salcedo
Copy link

salcedo commented Feb 3, 2019

Mosquitto version: 1.5.5

The following code is used to test LWT functionality in mosquitto over websockets.
There is a load balancer (traefik) that directs the websockets connection to mosquitto.

import signal
import sys
import time

import paho.mqtt.client as paho


client = paho.Client(
    client_id='tracking',
    transport='websockets',
)


def signal_handler(sig, frame):
    global client

    print('sending connection status: 0')
    client.publish('$CONNECTED/tracking', '0')
    time.sleep(5)
    sys.exit(0)


def publisher():
    global client

    client.username_pw_set('user', 'password')
    client.tls_set()
    client.will_set('$CONNECTED/tracking', payload='0 (lwt)', retain=True,
                    qos=2)

    client.connect('mosquitto.lan', 443, keepalive=5)
    client.loop_start()

    print('sending connection status: 1')
    client.publish('$CONNECTED/tracking', '1')

    while True:
        print('sending test message')
        client.publish('tracking/messages', 'test message')
        time.sleep(15)


if __name__ == '__main__':
    signal.signal(signal.SIGINT, signal_handler)
    publisher()

When there is an unclean disconnect (python script is killed with SIGKILL - not SIGINT), the LWT is sent, as expected.

However, unplugging the device's network cable to simulate a loss of connectivity results in mosquitto logging the following, and no LWT is ever sent:

1549215540: Client tracking has exceeded timeout, disconnecting.
1549215541: Socket error on client tracking, disconnecting.

Should a LWT be sent in this case? How is one to know when a client is offline if no LWT is sent on timeout?

@ralight
Copy link
Contributor

ralight commented Feb 3, 2019

It should be sent, the only case a MQTT 3.1.1 will shouldn't be sent is when the client sends a DISCONNECT. I'll take a look.

@ralight
Copy link
Contributor

ralight commented Feb 3, 2019

I've fixed this in my local branch which will be part of 1.5.6 soon. Thanks very much!

@ralight ralight closed this as completed Feb 3, 2019
@ralight ralight added this to the 1.5.6 milestone Feb 3, 2019
@karlp
Copy link
Contributor

karlp commented Feb 4, 2019

Was this a regression? I know I've tested cable pulling before.

@ralight
Copy link
Contributor

ralight commented Feb 5, 2019

Just on websockets, yes.

ralight added a commit that referenced this issue Feb 8, 2019
ralight added a commit that referenced this issue Apr 25, 2019
@copyrights
Copy link

I have a similar issue in 1.6.2

My client connects with:

MQ Telemetry Transport Protocol, Connect Command
    Header Flags: 0x10, Message Type: Connect Command
    Msg Len: 64
    Protocol Name Length: 4
    Protocol Name: MQTT
    Version: MQTT v3.1.1 (4)
    Connect Flags: 0xe4, User Name Flag, Password Flag, Will Retain, QoS Level: At most once delivery (Fire and Forget), Will Flag
        1... .... = User Name Flag: Set
        .1.. .... = Password Flag: Set
        ..1. .... = Will Retain: Set
        ...0 0... = QoS Level: At most once delivery (Fire and Forget) (0)
        .... .1.. = Will Flag: Set
        .... ..0. = Clean Session Flag: Not set
        .... ...0 = (Reserved): Not set
    Keep Alive: 60
    Client ID Length: 8
    Client ID: QuinLED4
    Will Topic Length: 15
    Will Topic: QuinLED4/status
    Will Message Length: 1
    Will Message: 0
    User Name Length: 8
    User Name: quinled4
    Password Length: 13
    Password: NotMyPassword

Then I unplug the client device and wait. As expected log shows:

1559035151: Client QuinLED4 has exceeded timeout, disconnecting.

But the LWT is not sent.

Here the full session with one subscriber from mosquitto log:

1559035024: mosquitto version 1.6.2 starting
1559035024: Config loaded from /mosquitto/config/mosquitto.conf.
1559035024: Opening ipv4 listen socket on port 1883.
1559035024: Opening ipv6 listen socket on port 1883.
1559035024: Opening ipv4 listen socket on port 8883.
1559035024: Opening ipv6 listen socket on port 8883.
1559035036: New connection from 192.168.159.28 on port 1883.
1559035037: New client connected from 192.168.159.28 as Monitor (p2, c1, k60, u'mqttfx').
1559035037: No will message specified.
1559035037: Sending CONNACK to Monitor (0, 0)
1559035043: Received SUBSCRIBE from Monitor
1559035043: 	QuinLED4/# (QoS 0)
1559035043: Monitor 0 QuinLED4/#
1559035043: Sending SUBACK to Monitor
1559035056: New connection from 192.168.159.83 on port 1883.
1559035056: New client connected from 192.168.159.83 as QuinLED4 (p2, c0, k60, u'quinled4').
1559035056: Will message specified (1 bytes) (r1, q0).
1559035056: 	QuinLED4/status
1559035056: Sending CONNACK to QuinLED4 (0, 0)
1559035057: Received UNSUBSCRIBE from QuinLED4
1559035057: 	#
1559035057: QuinLED4 #
1559035057: Sending UNSUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/brightness/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/brightness/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/mired/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/mired/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/kelvin/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/kelvin/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/channel/+/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/channel/+/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/relay/+/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/relay/+/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/pulse/+/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/pulse/+/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/led/+/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/led/+/set
1559035057: Sending SUBACK to QuinLED4
1559035057: Received SUBSCRIBE from QuinLED4
1559035057: 	QuinLED4/action/set (QoS 0)
1559035057: QuinLED4 0 QuinLED4/action/set
1559035057: Sending SUBACK to QuinLED4
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/app', ... (7 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/app', ... (7 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/version', ... (10 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/version', ... (10 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/board', ... (20 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/board', ... (20 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/host', ... (8 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/host', ... (8 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/ssid', ... (4 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/ssid', ... (4 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/ip', ... (14 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/ip', ... (14 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/mac', ... (17 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/mac', ... (17 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/rssi', ... (3 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/rssi', ... (3 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/uptime', ... (2 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/uptime', ... (2 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/datetime', ... (19 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/datetime', ... (19 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/freeheap', ... (5 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/freeheap', ... (5 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/relay/0', ... (1 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/relay/0', ... (1 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/mired', ... (3 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/mired', ... (3 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/channel/0', ... (1 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/channel/0', ... (1 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/channel/1', ... (3 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/channel/1', ... (3 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/brightness', ... (3 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/brightness', ... (3 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/vcc', ... (4 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/vcc', ... (4 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/status', ... (1 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/status', ... (1 bytes))
1559035060: Received PUBLISH from QuinLED4 (d0, q0, r1, m0, 'QuinLED4/loadavg', ... (3 bytes))
1559035060: Sending PUBLISH to Monitor (d0, q0, r0, m0, 'QuinLED4/loadavg', ... (3 bytes))
1559035103: Received PINGREQ from Monitor
1559035103: Sending PINGRESP to Monitor
1559035151: Client QuinLED4 has exceeded timeout, disconnecting.
1559035163: Received PINGREQ from Monitor
1559035163: Sending PINGRESP to Monitor
1559035201: Received DISCONNECT from Monitor
1559035201: Client Monitor disconnected.
1559035207: mosquitto version 1.6.2 terminating
1559035207: Saving in-memory database to /mosquitto/datamosquitto.db.

@lock lock bot locked as resolved and limited conversation to collaborators Aug 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants