diff --git a/ChangeLog.txt b/ChangeLog.txt index 18dbf2016e..28a04a47d8 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 fccece30f3..039b0d8944 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){