Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library is not compatible with latest version on socket.io 4.7.4 #360

Closed
Thioby opened this issue Feb 2, 2024 · 1 comment
Closed

Library is not compatible with latest version on socket.io 4.7.4 #360

Thioby opened this issue Feb 2, 2024 · 1 comment
Labels

Comments

@Thioby
Copy link

Thioby commented Feb 2, 2024

Hi, library is no longer compatible with latest socket.io. (4.7.4)
In latest version of socket.io there is list reserved events : https://github.com/socketio/socket.io-parser/blob/9f76ea22b41feeade0c8819dbf3c16fd07becc2a/lib/index.ts#L11

/**
 * These strings must not be used as event names, as they have a special meaning.
 */
const RESERVED_EVENTS = [
  "connect", // used on the client side
  "connect_error", // used on the client side
  "disconnect", // used on both sides
  "disconnecting", // used on the server side
  "newListener", // used by the Node.js EventEmitter
  "removeListener", // used by the Node.js EventEmitter
];

In this library list of events looks like this:

const List events = [
  'connect',
  'connect_error',
  'connect_timeout',
  'connecting',
  'disconnect',
  'error',
  'reconnect',
  'reconnect_attempt',
  'reconnect_failed',
  'reconnect_error',
  'reconnecting',
  'ping',
  'pong'
];

as you can see we are missing disconnecting event. Now flutter apps send disconnecting event as EVENT type: 2, but correct type is 1.

As a result, server side socket.io crash:

Error: invalid payload
   at Decoder.decodeString (/home/app/node_modules/socket.io-parser/build/cjs/index.js:238:23)
   at Decoder.add (/home/app/node_modules/socket.io-parser/build/cjs/index.js:141:27)
   at Client.ondata (/home/app/node_modules/socket.io/dist/client.js:182:26)
   at Socket.emit (node:events:517:28)
   at Socket.onPacket (/home/app/node_modules/engine.io/build/socket.js:120:22)
   at WebSocket.emit (node:events:517:28)
   at WebSocket.onPacket (/home/app/node_modules/engine.io/build/transport.js:94:14)
   at WebSocket.onData (/home/app/node_modules/engine.io/build/transport.js:103:14)
   at WebSocket.<anonymous> (/home/app/node_modules/engine.io/build/transports/websocket.js:20:19)
   at WebSocket.emit (node:events:517:28)
   at Receiver.receiverOnMessage (/home/app/node_modules/engine.io/node_modules/ws/lib/websocket.js:1178:20)
   at Receiver.emit (node:events:517:28)
   at Receiver.dataMessage (/home/app/node_modules/engine.io/node_modules/ws/lib/receiver.js:528:14)
   at Receiver.getData (/home/app/node_modules/engine.io/node_modules/ws/lib/receiver.js:446:17)
   at Receiver.startLoop (/home/app/node_modules/engine.io/node_modules/ws/lib/receiver.js:148:22)
   at Receiver._write (/home/app/node_modules/engine.io/node_modules/ws/lib/receiver.js:83:10)
   at writeOrBuffer (node:internal/streams/writable:392:12)
   at _write (node:internal/streams/writable:333:10)
   at Receiver.Writable.write (node:internal/streams/writable:337:10)
   at Socket.socketOnData (/home/app/node_modules/engine.io/node_modules/ws/lib/websocket.js:1272:35)
   at Socket.emit (node:events:517:28)
   at addChunk (node:internal/streams/readable:335:12)
   at readableAddChunk (node:internal/streams/readable:308:9)
   at Socket.Readable.push (node:internal/streams/readable:245:10)
   at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
   at TCP.callbackTrampoline (node:internal/async_hooks:130:17)

Error: invalid payload, type (2): \"[\"disconnecting\",\"transport close\"]\n

@Apidcloud
Copy link

Apidcloud commented Mar 18, 2024

Just to add some more info to whoever is searching for this issue. I think this happens at least since socket.io 4.6.2 (when they started using socket.io-parser 4.2.4 with the RESERVED_EVENTS listed above).

And just to clarify: should we upgrade to socket io client-dart 3.x beta? or is it something we could avoid by downgrading socket.io to 4.6.1 (and/or force socket.io-parser 4.2.3)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants