From 4b62474234b1acfe63751e8a5430c62d6c8c8d7c Mon Sep 17 00:00:00 2001 From: ravinsp <33562092+ravinsp@users.noreply.github.com> Date: Thu, 28 May 2020 22:42:00 +0530 Subject: [PATCH] websocketd close() workaround. --- src/comm/comm_server.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/comm/comm_server.cpp b/src/comm/comm_server.cpp index d1f64aa7..47a49ff9 100644 --- a/src/comm/comm_server.cpp +++ b/src/comm/comm_server.cpp @@ -125,7 +125,18 @@ void comm_server::connection_watchdog( if (!should_disconnect) { if (result & POLLIN) + { should_disconnect = (session.attempt_read(max_msg_size) == -1); + if (should_disconnect) + { + // Workaround to get websocketd to close the connection properly. + // This can be removed once websocketd issue is fixed. + // We are triggering this condition: + // https://github.com/codetsunami/websocketd/blob/c010d8b81dd48bd5948949946f31eacecf591071/libwebsocketd/process_endpoint.go#L141 + const uint32_t large_header = UINT32_MAX; + write(fd, &large_header, sizeof(uint32_t)); + } + } if (result & (POLLERR | POLLHUP | POLLRDHUP | POLLNVAL)) should_disconnect = true;