diff --git a/ChangeLog.txt b/ChangeLog.txt index 9a1abd42e3..975fb8a115 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -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 diff --git a/src/handle_connect.c b/src/handle_connect.c index dcc8ea5c19..790c88a2b0 100644 --- a/src/handle_connect.c +++ b/src/handle_connect.c @@ -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); } diff --git a/test/broker/01-connect-take-over.py b/test/broker/01-connect-take-over.py new file mode 100755 index 0000000000..a275ad7e1e --- /dev/null +++ b/test/broker/01-connect-take-over.py @@ -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) diff --git a/test/broker/Makefile b/test/broker/Makefile index 5883645cad..63b9ae8f25 100644 --- a/test/broker/Makefile +++ b/test/broker/Makefile @@ -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 diff --git a/test/broker/test.py b/test/broker/test.py index 26361c568a..e034a83d32 100755 --- a/test/broker/test.py +++ b/test/broker/test.py @@ -10,6 +10,7 @@ (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'),