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

Websocket stuck after receiving around ~16 kb of data from client #80

Closed
zmeyc opened this issue Oct 7, 2020 · 3 comments · Fixed by #81
Closed

Websocket stuck after receiving around ~16 kb of data from client #80

zmeyc opened this issue Oct 7, 2020 · 3 comments · Fixed by #81

Comments

@zmeyc
Copy link
Contributor

zmeyc commented Oct 7, 2020

🐛 Bug Report

After client sends ~100 messages of ~160 bytes each to websocket, connection.socket.on('message') is no longer being triggered.

It seems to be size-dependent, I can send thousands of very short (a few bytes) messages, but only around 100 lines of 160 bytes.

To Reproduce

In new dir:

yarn init
yarn add fastify fastify-websocket

Create server.js:

'use strict'

const fastify = require('fastify')()

fastify.register(require('fastify-websocket'))

fastify.get('/', { websocket: true }, (connection, req) => {
  connection.socket.on('message', message => {
    // message === 'hi from client'
    connection.socket.send('hi from server')
  })
})

fastify.listen(5000, err => {
  if (err) {
    fastify.log.error(err)
    process.exit(1)
  }

Run node server.js

In another window, run:

wscat --show-ping-pong -c "ws://localhost:5000"

Create a file with ~150 lines of 160 bytes each. Copy-paste contents into wscat.

The server will stop responding.

Expected behavior

Should keep returning responses.

Your Environment

  • node version: 12
  • fastify version: >=2.0.0
  • os: Mac, Linux
@mcollina
Copy link
Member

mcollina commented Oct 7, 2020

Which version are you using? We fixed this in #78.

@zmeyc
Copy link
Contributor Author

zmeyc commented Oct 7, 2020

@mcollina latest one, 2.0.9

@zmeyc
Copy link
Contributor Author

zmeyc commented Oct 7, 2020

I checked that pure ws@7.3.1 with default settings works stably (without calling connection.resume()):

import WebSocket from 'ws'
const webSocketServer = new WebSocket.Server({ port: websocketPort })
webSocketServer.on('connection', function connection(ws) {
  ws.on('message', function incoming(message) {
    console.log('received: %s', message)
    ws.send(`got ${message}`)
  })
  ws.send('connected')
})

mcollina pushed a commit that referenced this issue Oct 8, 2020
* fix: Resume connection stream before continuing. [#80]

* chore: Remove redundant listener.

* chore: Linted code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants