socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
60.99k stars 10.1k forks source link

Socket.io-client 4.8.0 with Node native WebSocket 'Maximum call stack size exceeded' exception when closing the connection #5194

Open vpmedia opened 1 week ago

vpmedia commented 1 week ago

Describe the bug Using socket.io 4.8.0 server and socket.io-client 4.8.0 with native Node v21+ web socket transport I'm getting the following exception when the connection is closed between the client and the server. The WebSocket client is running server side using the new transport WebSocket option added in v4.8.0.

process.on('uncaughtException') log: (this is unexpected)

error: [Server] uncaughtException Maximum call stack size exceeded {"stack":"RangeError: Maximum call stack size exceeded\n    at emitInitScript (node:internal/async_hooks:495:24)\n    at process.nextTick (node:internal/process/task_queues:143:5)\n    at emitUncaughtException (node:internal/event_target:1090:11)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:824:9)\n    at WebSocket.dispatchEvent (node:internal/event_target:751:26)\n    at fireEvent (node:internal/deps/undici/undici:11340:14)\n    at failWebsocketConnection (node:internal/deps/undici/undici:11421:9)\n    at closeWebSocketConnection (node:internal/deps/undici/undici:11692:9)\n    at WebSocket.close (node:internal/deps/undici/undici:12352:9)\n    at WS.doClose (file:///REDACTED/node_modules/engine.io-client/build/esm-debug/transports/websocket.js:83:21)"}

socket.on('connect_error') log: (this is expected)

error: [Entity] onConnectError websocket error {"description":{},"stack":"Error: websocket error\n    at WS.onError (file:///REDACTED/node_modules/engine.io-client/build/esm-debug/transport.js:41:37)\n    at ws.onerror (file:///REDACTED/node_modules/engine.io-client/build/esm-debug/transports/websocket.js:51:39)\n    at [nodejs.internal.kHybridDispatch] (node:internal/event_target:816:20)\n    at WebSocket.dispatchEvent (node:internal/event_target:751:26)\n    at fireEvent (node:internal/deps/undici/undici:11340:14)\n    at failWebsocketConnection (node:internal/deps/undici/undici:11421:9)\n    at Object.processResponse (node:internal/deps/undici/undici:11635:13)\n    at node:internal/deps/undici/undici:10425:23\n    at node:internal/process/task_queues:151:7\n    at AsyncResource.runInAsyncScope (node:async_hooks:211:14)","type":"TransportError"}
vpmedia commented 1 week ago

I've created a repository with a minimal example to reproduce the issue: https://github.com/vpmedia/socketio-issue

my node version is v22.9.0 my system is macOS 15.0 / Apple M3 Max