From 8234d24b1b08e1f15353828649ca3290f67ea455 Mon Sep 17 00:00:00 2001 From: "Roger A. Light" Date: Wed, 15 Jul 2020 22:06:29 +0100 Subject: [PATCH] Fix websockets clients sometimes not being disconnected promptly. Closes #1718. Thanks to Luca Casonato. --- ChangeLog.txt | 2 ++ src/websockets.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/ChangeLog.txt b/ChangeLog.txt index 18dbf201..28a04a47 100644 --- a/ChangeLog.txt +++ b/ChangeLog.txt @@ -11,6 +11,8 @@ Broker: set to true. Closes #1729. - Fix `autosave_interval` not being triggered by messages being delivered. Closes #1726. +- Fix websockets clients sometimes not being disconnected promptly. + Closes #1718. Client library: - Improved documentation around connect callback return codes. Close #1730. diff --git a/src/websockets.c b/src/websockets.c index fccece30..039b0d89 100644 --- a/src/websockets.c +++ b/src/websockets.c @@ -302,7 +302,10 @@ static int callback_mqtt(struct libwebsocket_context *context, } count = libwebsocket_write(wsi, &packet->payload[packet->pos], txlen, LWS_WRITE_BINARY); if(count < 0){ - if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){ + if (mosq->state == mosq_cs_disconnect_ws + || mosq->state == mosq_cs_disconnecting + || mosq->state == mosq_cs_disused){ + return -1; } return 0; @@ -313,7 +316,10 @@ static int callback_mqtt(struct libwebsocket_context *context, packet->to_process -= count; packet->pos += count; if(packet->to_process > 0){ - if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){ + if (mosq->state == mosq_cs_disconnect_ws + || mosq->state == mosq_cs_disconnecting + || mosq->state == mosq_cs_disused){ + return -1; } break; @@ -340,7 +346,10 @@ static int callback_mqtt(struct libwebsocket_context *context, mosq->next_msg_out = mosquitto_time() + mosq->keepalive; } - if (mosq->state == mosq_cs_disconnect_ws || mosq->state == mosq_cs_disconnecting){ + if (mosq->state == mosq_cs_disconnect_ws + || mosq->state == mosq_cs_disconnecting + || mosq->state == mosq_cs_disused){ + return -1; } if(mosq->current_out_packet){