help icon indicating copy to clipboard operation
help copied to clipboard

Socket Freeze Issue During High Data Volume in Node.js Application

Open Gabriel-id opened this issue 1 year ago • 3 comments

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 avatar Mar 20 '24 13:03 Gabriel-id

@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.write in the callback itself?

gireeshpunathil avatar Mar 21 '24 08:03 gireeshpunathil

@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.write in the callback itself?
  • Some MBs
  • Yes, it would be possible. It was just one of the tests I was conducting.

Gabriel-id avatar Mar 21 '24 12:03 Gabriel-id

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?

gireeshpunathil avatar Mar 21 '24 14:03 gireeshpunathil

Closing as it's been 2 weeks without a reply to the suggestion in https://github.com/nodejs/help/issues/4361#issuecomment-2012508524.

Trott avatar Apr 05 '24 15:04 Trott