socketio / socket.io

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

Engine.io: Cannot read properties of undefined (reading 'end') error #4643

Closed azju closed 1 month ago

azju commented 1 year ago

Describe the bug We're sometimes seeing a very rare error while using uWebSockets.js (uws);

To Reproduce

It happens occasionally and can't reproduce locally

Socket.IO server version: 4.6.0

Expected behavior No to see the error or this error gets handled gracefully.

Platform:

Additional context Cannot read properties of undefined (reading 'end')\nTypeError: Cannot read properties of undefined (reading 'end')\n at Polling.onDataRequest (/node_modules/engine.io/build/transports-uws/polling.js:104:51)\n at Polling.onRequest (/node_modules/engine.io/build/transports-uws/polling.js:47:18)\n at /node_modules/engine.io/build/userver.js:95:60\n at uServer.verify (/node_modules/engine.io/build/server.js:152:9)\n at /node_modules/engine.io/build/userver.js:82:18\n at /node_modules/engine.io/build/userver.js:74:13\n at /node_modules/engine.io/build/server.js:187:21\n at cors (/node_modules/cors/lib/index.js:188:7)\n at /node_modules/cors/lib/index.js:224:17\n at origin (/dist/socket.js:40:25)

darrachequesne commented 1 year ago

I think I've found the culprit, this should be fixed by https://github.com/socketio/engine.io/commit/8b2216290330b174c9e67be32765bec0c74769f9, included in engine.io@6.4.2 and thus in socket.io@4.6.x.

Please reopen if needed.

joacub commented 1 year ago

socket.io

not, it does not fix that, also there is other error with uws

dubisoft-solutions commented 1 year ago

we are facing a similar issues

TypeError: Cannot read property 'end' of undefined

at IncomingMessage.onData (/usr/local/readytech/acc-server/stage/node_modules/engine.io/build/transports/polling.js:128:35)
 at IncomingMessage.emit (events.js:197:13)
 at addChunk (_stream_readable.js:288:12)
 at readableAddChunk (_stream_readable.js:265:13)
 at IncomingMessage.Readable.push (_stream_readable.js:224:10)
 at HTTPParser.parserOnBody (_http_common.js:126:22)
Jul 20 08:07:58 dev-server systemd[1]: service: Main process exited, code=exited, status=1/FAILURE
darrachequesne commented 1 month ago

For future readers:

The exception seems to come from this line: https://github.com/socketio/socket.io/blob/132d05fc0b319df7eb1b3010a91adc7d5ae58ef2/packages/engine.io/lib/transports/polling.ts#L154

Though I'm not sure how res.writeHead(413).end(); can result in TypeError: Cannot read property 'end' of undefined.

I do think the initial issue was fixed though. Please reopen if needed.