Skip to content

Commit

Permalink
Fix incorrect return code being sent in DISCONNECT.
Browse files Browse the repository at this point in the history
This is for when a client session is taken over.

Closes #2607. Thanks to der-b
  • Loading branch information
ralight committed Aug 10, 2022
1 parent 08610f7 commit 351911b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/handle_connect.c
Expand Up @@ -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);
}

Expand Down
34 changes: 34 additions & 0 deletions 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)
1 change: 1 addition & 0 deletions test/broker/Makefile
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/broker/test.py
Expand Up @@ -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'),
Expand Down

0 comments on commit 351911b

Please sign in to comment.