Fix incorrect return code being sent in DISCONNECT.

This is for when a client session is taken over.

Closes #2607. Thanks to der-b
This commit is contained in:
Roger A. Light 2022-08-10 14:09:47 +01:00
parent 08610f7c99
commit 351911bd8f
5 changed files with 42 additions and 0 deletions

View File

@ -16,6 +16,8 @@ Broker:
- Fix bridges not sending failure notification messages to the local broker if
the remote bridge connection fails. Closes #2467. Closes #1488.
- Fix some PUBLISH messages not being counted in $SYS stats. Closes #2448.
- Fix incorrect return code being sent in DISCONNECT when a client session is
taken over. Closes #2607.
Client library:
- Fix threads library detection on Windows under cmake. Bumps the minimum

View File

@ -205,6 +205,10 @@ int connect__on_authorised(struct mosquitto *context, void *auth_data_out, uint1
found_context->clean_start = true;
found_context->session_expiry_interval = 0;
mosquitto__set_state(found_context, mosq_cs_duplicate);
if(found_context->protocol == mosq_p_mqtt5){
send__disconnect(found_context, MQTT_RC_SESSION_TAKEN_OVER, NULL);
}
do_disconnect(found_context, MOSQ_ERR_SUCCESS);
}

View File

@ -0,0 +1,34 @@
#!/usr/bin/env python3
# MQTT v5 session takeover test
from mosq_test_helper import *
port = mosq_test.get_port()
broker = mosq_test.start_broker(filename=os.path.basename(__file__), port=port)
try:
rc = 1
connect_packet = mosq_test.gen_connect("take-over", proto_ver=5)
connack_packet = mosq_test.gen_connack(rc=0, proto_ver=5)
disconnect_packet = mosq_test.gen_disconnect(reason_code=mqtt5_rc.MQTT_RC_SESSION_TAKEN_OVER, proto_ver=5)
sock1 = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
sock2 = mosq_test.do_client_connect(connect_packet, connack_packet, port=port)
mosq_test.expect_packet(sock1, "disconnect", disconnect_packet)
mosq_test.do_ping(sock2)
sock2.close()
sock1.close()
rc = 0
except mosq_test.TestError:
pass
except Exception as e:
print(e)
finally:
broker.terminate()
broker.wait()
(stdo, stde) = broker.communicate()
if rc:
print(stde.decode('utf-8'))
exit(rc)

View File

@ -28,6 +28,7 @@ msg_sequence_test:
./01-connect-disconnect-v5.py
./01-connect-max-connections.py
./01-connect-max-keepalive.py
./01-connect-take-over.py
./01-connect-uname-no-password-denied.py
./01-connect-uname-or-anon.py
./01-connect-uname-password-denied-no-will.py

View File

@ -10,6 +10,7 @@ tests = [
(1, './01-connect-disconnect-v5.py'),
(1, './01-connect-max-connections.py'),
(1, './01-connect-max-keepalive.py'),
(1, './01-connect-take-over.py'),
(1, './01-connect-uname-no-password-denied.py'),
(1, './01-connect-uname-or-anon.py'),
(1, './01-connect-uname-password-denied-no-will.py'),