Skip to content

Commit

Permalink
Fix LWT messages not being delivered if per_listener_settings was s…
Browse files Browse the repository at this point in the history
…et to true

Closes eclipse#2314. Thanks to Marc Hamel.
  • Loading branch information
ralight committed Sep 21, 2021
1 parent d942ed7 commit 7551a29
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

Broker:
- Fix `max_keepalive` option not being able to be set to 0.
- Fix LWT messages not being delivered if `per_listener_settings` was set to
true. Closes #2314.


2.0.12 - 2021-08-31
Expand Down
3 changes: 1 addition & 2 deletions src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,8 @@ void context__disconnect(struct mosquitto *context)

plugin__handle_disconnect(context, -1);

net__socket_close(context);

context__send_will(context);
net__socket_close(context);
if(context->session_expiry_interval == 0){
/* Client session is due to be expired now */
#ifdef WITH_BRIDGE
Expand Down
58 changes: 58 additions & 0 deletions test/broker/07-will-per-listener.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python3

# Test whether a client will is transmitted correctly, with per_listener_settings enabled

from mosq_test_helper import *

def write_config(filename, port):
with open(filename, 'w') as f:
f.write("per_listener_settings true\n")
f.write("listener %d\n" % (port))
f.write("allow_anonymous true\n")

def do_test(proto_ver, clean_session):
rc = 1
mid = 53
connect1_packet = mosq_test.gen_connect("will-qos0-test", proto_ver=proto_ver)
connack1_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)

connect2_packet = mosq_test.gen_connect("test-helper", will_topic="will/qos0/test", will_payload=b"will-message", clean_session=clean_session, proto_ver=proto_ver, session_expiry=60)
connack2_packet = mosq_test.gen_connack(rc=0, proto_ver=proto_ver)

subscribe_packet = mosq_test.gen_subscribe(mid, "will/qos0/test", 0, proto_ver=proto_ver)
suback_packet = mosq_test.gen_suback(mid, 0, proto_ver=proto_ver)

publish_packet = mosq_test.gen_publish("will/qos0/test", qos=0, payload="will-message", proto_ver=proto_ver)

port = mosq_test.get_port()
conf_file = os.path.basename(__file__).replace('.py', '.conf')
write_config(conf_file, port)
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port, use_conf=True)

try:
sock = mosq_test.do_client_connect(connect1_packet, connack1_packet, timeout=5, port=port)
mosq_test.do_send_receive(sock, subscribe_packet, suback_packet, "suback")

sock2 = mosq_test.do_client_connect(connect2_packet, connack2_packet, port=port, timeout=5)
sock2.close()

mosq_test.expect_packet(sock, "publish", publish_packet)
rc = 0

sock.close()
except mosq_test.TestError:
pass
finally:
os.remove(conf_file)
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
exit(rc)

do_test(4, True)
do_test(4, False)
do_test(5, True)
do_test(5, False)
exit(0)
1 change: 1 addition & 0 deletions test/broker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ msg_sequence_test:
./07-will-null-topic.py
./07-will-null.py
./07-will-oversize-payload.py
./07-will-per-listener.py
./07-will-properties.py
./07-will-qos0.py
./07-will-reconnect-1273.py
Expand Down
1 change: 1 addition & 0 deletions test/broker/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
(1, './07-will-null-topic.py'),
(1, './07-will-null.py'),
(1, './07-will-oversize-payload.py'),
(1, './07-will-per-listener.py'),
(1, './07-will-properties.py'),
(1, './07-will-qos0.py'),
(1, './07-will-reconnect-1273.py'),
Expand Down

0 comments on commit 7551a29

Please sign in to comment.