Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Server crashes when you unexpectedly drop an established websocket connection. #1

Open
ratacat opened this issue Dec 28, 2018 · 5 comments
Labels
bug Something isn't working

Comments

@ratacat
Copy link

ratacat commented Dec 28, 2018

`events.js:167
throw er; // Unhandled 'error' event
^

Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:139:27)
Emitted 'error' event at:
at WebSocket.finalize (/Users/jared/Dev/ranviermud/bundles/ranvier-websocket/node_modules/ws/lib/WebSocket.js:182:41)
at Socket.emit (events.js:182:13)
at emitErrorNT (internal/streams/destroy.js:82:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:50:3)
at process.internalTickCallback (internal/process/next_tick.js:72:19)`

I seem to be able to replicate it pretty easily by simply connecting to the server with Neuro (which I'm running in a browser) and then closing the browser tab after I've already logged in to a character.

@shawncplus shawncplus added the bug Something isn't working label Dec 28, 2018
@seanohue
Copy link

seanohue commented Feb 4, 2019

Would using socket.io be a good fix for that, or is that excessive? I ask only because AFAIK socket.io already has this sort of error handling and much more. Or would it be better to create a socket-io-networking bundle?

@shawncplus
Copy link
Member

A separate socket io bundle would be quite cool.

@Ryxias
Copy link

Ryxias commented Feb 25, 2019

A working solution I found is related to this thread and this comment in the ws repo.

Upon every new inbound connection, attach an error listener to the websocket that is created:

      // This creates a super basic "echo" websocket server
      wss.on('connection', function connection(ws) {

        // ------ Add error handler
        ws.on('error', (err) => {
          // Ignore network errors like `ECONNRESET`, `EPIPE`, etc.
          if (err.errno) return;
          Logger.error(err);
          throw err;
        });
        // ---------
        
        // create our adapter
        const stream = new WebsocketStream();
        // and attach the raw websocket
        stream.attach(ws);

        // Register all of the input events (login, etc.)
        state.InputEventManager.attach(stream);

        stream.write("Connecting...\n");
        Logger.log("User connected via websocket...");

        // @see: bundles/ranvier-events/events/login.js
        stream.emit('intro', stream);
      });
      Logger.log(`Websocket server started on port: ${wss.options.port}...`);
    },

@seanohue
Copy link

I like this as a good-enough solution, then if people want to do different handling for specific errors they can easily add their own listeners to the socket IIRC.

@AlanFonderflick
Copy link

I upgraded ws to latest and made a yarn install in the bundle and it worked fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants