Socket Freeze Issue During High Data Volume in Node.js Application
Details
I'm having a problem with a Node.js application. This application is a client that reads data from a TCP connection using net.socket. When there's a sudden surge in data volume, the socket appears to freeze, preventing further data arrival. After a period of being stuck, the socket unlocks, and the previously withheld data starts arriving, as if it had been temporarily held back and then released.
Node.js version
18.7.1
Example code
const connect = require('node:net').connect
const PassThrough = require('node:stream').PassThrough
const TELNET_HOST = process.env.TELNET_HOST
const TELNET_PORT = process.env.TELNET_PORT
const broadcaster = new PassThrough()
const socket = connect(
{
host: TELNET_HOST,
port: TELNET_PORT,
onread: {
buffer: Buffer.alloc(32 * 1024),
callback: (nread, buffer) => socket.emit('data', buffer.subarray(0, nread)),
},
},
() => console.info('Connected')
)
socket.on('data', (data) => broadcaster.write(data))
Operating system
Linux
Scope
code and runtime
Module and version
Not applicable.
@Gabriel-id -
- when you say sudden surge in data volume, what is it like? MBs? GBs? TBs?
- why are you re-emitting? can't you do
broadcaster.writein the callback itself?
@Gabriel-id -
- when you say sudden surge in data volume, what is it like? MBs? GBs? TBs?
- why are you re-emitting? can't you do
broadcaster.writein the callback itself?
- Some MBs
- Yes, it would be possible. It was just one of the tests I was conducting.
Yes, it would be possible. It was just one of the tests I was conducting.
ok - try that. i.e, omit the unread callback and just do things in socket.on(data) callback and see if it removes the freeze?
Closing as it's been 2 weeks without a reply to the suggestion in https://github.com/nodejs/help/issues/4361#issuecomment-2012508524.