nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.89k stars 7.56k forks source link

Crash and ECONNRESET with websocket on chrome #992

Closed ospfranco closed 6 years ago

ospfranco commented 6 years ago

I'm submitting a...


[ ] Regression 
[ x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

I'm using a plain websocket connection to the nestjs server, everything works fine except on chrome, when I refresh the page, the server gets a ECONNRESET exception and it completely crashes.

May be related to https://github.com/websockets/ws/issues/1256?

Expected behavior

Gracefully handle socket termination

Minimal reproduction of the problem with instructions

Create a normal websocket client (non socket.io) on chrome Connect to nestjs via websocket (I'm using one of the examples: https://github.com/nestjs/nest/tree/master/sample/02-gateways) Hit refresh Server will crash

What is the motivation / use case for changing the behavior?

Server crashing bug

Environment


Nest version: 5.0.1


For Tooling issues:
- Node version: 8.1.4  
- Platform:  Mac


kamilmysliwiec commented 6 years ago

Update framework to the latest version (v5.2.0) and afterward, check this sample again. Everything should work fine :) If you face any issues, please, let me know

ospfranco commented 6 years ago

just tested it, still crashing on 5.2.1.

Found a workaround, on the socket gateway:

import { SubscribeMessage, WebSocketGateway, WebSocketServer, WsResponse, OnGatewayConnection } from '@nestjs/websockets';

@WebSocketGateway()
export default class SocketGateway implements OnGatewayConnection {
   public handleConnection(client: any) {
    client.on('error', (err) => {
      console.log(err);
    });
  }

...
lock[bot] commented 4 years ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.