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

No rooms on client upgrade using uWebSockets.js

Open stevestevensonneds opened this issue 3 years ago • 0 comments

Describe the bug

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

TypeError: Cannot read properties of undefined (reading 'forEach')
    at subscribe (/node_modules/socket.io/dist/uws.js:87:11)
    at Socket.<anonymous> (/node_modules/socket.io/dist/uws.js:28:17)
    at Socket.emit (node:events:402:35)
    at WebSocket.onPacket (/node_modules/engine.io/build/socket.js:214:22)
    at WebSocket.emit (node:events:390:28)
    at WebSocket.onPacket (/node_modules/engine.io/build/transport.js:92:14)
    at WebSocket.onData (/node_modules/engine.io/build/transport.js:101:14)
    at message (/node_modules/engine.io/build/userver.js:56:30)"

Stack trace mapped to source

https://github.com/socketio/socket.io/blob/main/lib/uws.ts#L104
https://github.com/socketio/socket.io/blob/main/lib/uws.ts#L28
https://github.com/socketio/engine.io/blob/main/lib/socket.ts#L274
https://github.com/socketio/engine.io/blob/main/lib/transport.ts#L116
https://github.com/socketio/engine.io/blob/main/lib/transport.ts#L126
https://github.com/socketio/engine.io/blob/main/lib/userver.ts#L84

It seems to be when the client upgrades but is not in any rooms.

Expected behavior

Upgrade a connection without causing an error trying to subscribe to an omitted rooms argument.

Platform:

  • Client device: Unknown
  • Client OS: Unknown
  • Server: x86_64 & arm64 Alpine linux
  • Socket.IO version: 4.5.1
  • Engine.IO version: 6.2.0
  • uWebSockets.js version: 20.10.0

stevestevensonneds avatar Aug 08 '22 00:08 stevestevensonneds

I could indeed reproduce the issue, thanks a lot for the report :+1:

This should be fixed by https://github.com/socketio/socket.io/commit/ba497ee3eb52c4abf1464380d015d8c788714364, included in version 4.5.2.

Please reopen if needed.

darrachequesne avatar Sep 04 '22 20:09 darrachequesne