Skip to content

fix: track socket before run middlewares #5158

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions packages/socket.io/lib/namespace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,9 @@ export class Namespace<
debug("adding socket to nsp %s", this.name);
const socket = await this._createSocket(client, auth);

// track socket
this.sockets.set(socket.id, socket);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm not sure about this change, since the sockets map currently contains only sockets that are actually connected (not in the process of connection).


if (
// @ts-ignore
this.server.opts.connectionStateRecovery?.skipMiddlewares &&
Expand Down Expand Up @@ -389,9 +392,6 @@ export class Namespace<
socket: Socket<ListenEvents, EmitEvents, ServerSideEvents, SocketData>
) => void
) {
// track socket
this.sockets.set(socket.id, socket);

// it's paramount that the internal `onconnect` logic
// fires before user-set events to prevent state order
// violations (such as a disconnection before the connection
Expand Down