Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hello,

Sometimes we have unexpected websocket disconnect in event/nio.c
static void nio_read(hio_t* io) {
...
if (nread == 0 && (io->io_type & HIO_TYPE_SOCK_STREAM)) {
goto disconnect;
}
...

Our guess that it happens not because opposite side closed connection, but just because lack of data in the socket.

We tried this patch

diff --git a/event/nio.c b/event/nio.c
index 7ebea8d..0bb09e7 100644
--- a/event/nio.c
+++ b/event/nio.c
@@ -7,6 +7,10 @@
 #include "herr.h"
 #include "hthread.h"
 
+#ifdef _WIN32
+#include <windows.h>
+#endif
+
 static void __connect_timeout_cb(htimer_t* timer) {
     hio_t* io = (hio_t*)timer->privdata;
     if (io) {
@@ -331,6 +335,16 @@ read:
         }
     }
     if (nread == 0 && (io->io_type & HIO_TYPE_SOCK_STREAM)) {
+        err = socket_errno();
+#ifdef _WIN32
+        if (err == WSAEWOULDBLOCK)
+#else
+        if (err == EAGAIN || err == EINTR)
+#endif
+        {
+          return;
+        }
+
         goto disconnect;
     }
     if (nread < len) {

It works fine for us.

Could you check if it is correct and apply it, if yes?

Thank you in advance
Vladimir

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant
Morty Proxy This is a proxified and sanitized view of the page, visit original site.