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

Auth duplicates connect messages #4755

Open
constantant opened this issue Jun 30, 2023 · 1 comment
Open

Auth duplicates connect messages #4755

constantant opened this issue Jun 30, 2023 · 1 comment
Labels
question Further information is requested

Comments

@constantant
Copy link

constantant commented Jun 30, 2023

Describe the bug
In case calling Manager's method socket with the auth data it emits two auth messages which causes an error

To Reproduce

Please fill the following code example:

Socket.IO client version: 4.7.1

Client

import { Manager } from "socket.io-client";

const manager = new Manager("ws://localhost:3000/", {transports: ['websocket'], upgrade: false});

const socket = manager.socket('my-namespace', { auth: { 'X-Auth': 'XXX-XXX-XXX' } });

socket.on("connect", () => {
  // at this moment it is already failed
  console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
  console.log("disconnect");
});

Expected behavior
At moment a first connect callback is set the socket must be 100% connected.

Platform:

  • Device: Dell Latitude
  • OS: Windows 10

Workaround
#474 (comment)

@constantant constantant added the to triage Waiting to be triaged by a member of the team label Jun 30, 2023
@darrachequesne
Copy link
Member

Hi! I think that's because you are missing a "/" at the beginning of the namespace, it should rather be:

const socket = manager.socket('/my-namespace', { auth: { 'X-Auth': 'XXX-XXX-XXX' } });

Output:

$ DEBUG=socket* node client.js 
  socket.io-client:manager readyState closed +0ms
  socket.io-client:manager opening ws://localhost:3000/ +1ms
  socket.io-client:manager connect attempt will timeout after 20000 +6ms
  socket.io-client:manager readyState opening +0ms
  socket.io-client:manager open +9ms
  socket.io-client:manager cleanup +0ms
  socket.io-client:socket transport is open - connecting +0ms
  socket.io-client:manager writing packet {"type":0,"data":{"X-Auth":"XXX-XXX-XXX"},"nsp":"/my-namespace"} +0ms
  socket.io-parser encoding packet {"type":0,"data":{"X-Auth":"XXX-XXX-XXX"},"nsp":"/my-namespace"} +0ms
  socket.io-parser encoded {"type":0,"data":{"X-Auth":"XXX-XXX-XXX"},"nsp":"/my-namespace"} as 0/my-namespace,{"X-Auth":"XXX-XXX-XXX"} +0ms
  socket.io-parser decoded 0/my-namespace,{"sid":"qU0TCPiLzrIsNVEyAAAB"} as {"type":0,"nsp":"/my-namespace","data":{"sid":"qU0TCPiLzrIsNVEyAAAB"}} +4ms
  socket.io-client:socket socket connected with id qU0TCPiLzrIsNVEyAAAB +4ms
connect qU0TCPiLzrIsNVEyAAAB
  socket.io-client:socket draining queue +1ms

@darrachequesne darrachequesne added question Further information is requested and removed to triage Waiting to be triaged by a member of the team labels Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants