Skip to content

Commit

Permalink
Fix persistent Websockets clients not receiving messages.
Browse files Browse the repository at this point in the history
This occurs after they reconnect, having sent DISCONNECT
on a previous session.

Closes eclipse#1227. Thanks to usernametaken.
  • Loading branch information
ralight authored and vankxr committed Aug 9, 2019
1 parent 46fb82d commit 1a655e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -18,6 +18,8 @@ Broker:
#1276.
- Add 'extern "C"' on mosquitto_broker.h and mosquitto_plugin.h for C++ plugin
writing. Closes #1290.
- Fix persistent Websockets clients not receiving messages after they
reconnect, having sent DISCONNECT on a previous session. Closes #1227.

Client library:
- Fix typo causing build error on Windows when building without TLS support.
Expand Down
17 changes: 16 additions & 1 deletion src/loop.c
Expand Up @@ -614,12 +614,19 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context, int reaso
#ifdef WITH_EPOLL
struct epoll_event ev;
#endif
#ifdef WITH_WEBSOCKETS
bool is_duplicate = false;
#endif

if(context->state == mosq_cs_disconnected){
return;
}
#ifdef WITH_WEBSOCKETS
if(context->wsi){
if(context->state == mosq_cs_duplicate){
is_duplicate = true;
}

if(context->state != mosq_cs_disconnecting && context->state != mosq_cs_disconnect_with_will){
context__set_state(context, mosq_cs_disconnect_ws);
}
Expand All @@ -636,7 +643,15 @@ void do_disconnect(struct mosquitto_db *db, struct mosquitto *context, int reaso
context->sock = INVALID_SOCKET;
context->pollfd_index = -1;
}
context__remove_from_by_id(db, context);
if(is_duplicate){
/* This occurs if another client is taking over the same client id.
* It is important to remove this from the by_id hash here, so it
* doesn't leave us with multiple clients in the hash with the same
* id. Websockets doesn't actually close the connection here,
* unlike for normal clients, which means there is extra time when
* there could be two clients with the same id in the hash. */
context__remove_from_by_id(db, context);
}
}else
#endif
{
Expand Down

0 comments on commit 1a655e9

Please sign in to comment.