engine.io icon indicating copy to clipboard operation
engine.io copied to clipboard

maxHttpBufferSize violation silently disconnects client with no error event

Open yujiang opened this issue 7 months ago • 0 comments

Summary

When a client sends a message that exceeds the maxHttpBufferSize, the server closes the connection immediately with no way for the developer to detect or handle the error properly.

Expected Behavior

There should be a proper 'error' event (e.g., 'error', 'packetError', or 'close' with a specific reason), or a packet with error metadata that allows distinguishing "oversized payload" from a general transport error.

Actual Behavior

  • Server does NOT trigger socket.on('big-message')
  • socket.conn.on('error') is NOT called
  • Only socket.on('disconnect') is called with reason 'transport error'
  • No detailed error message available

Why this matters

This makes it impossible to distinguish between an oversized payload vs. a broken connection, which causes:

  • Inaccurate logging / monitoring
  • Inability to handle abuse cases
  • Poor developer experience when debugging

Minimal Repro

// Server (Node.js)
const io = new Server(server, {
  maxHttpBufferSize: 1e6
});
io.on('connection', (socket) => {
  socket.on('big-message', (data) => {
    console.log('Received:', data.length);
  });
  socket.on('disconnect', (reason) => {
    console.log('Disconnected:', reason);
  });
});

// Client (Browser or Node)
const socket = io('http://localhost:3000', { reconnection: false });
const big = 'x'.repeat(2 * 1024 * 1024); // 2MB
socket.emit('big-message', big);

yujiang avatar May 07 '25 14:05 yujiang