-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
The docs for the disconnect
event state:
In all cases but the first (disconnection by the server), the client will wait for a small random delay and then reconnect.
In what I've experienced + what I can see from reading the socket.io-client
source code, this is not true. Disconnection by the client does not cause a reconnect. Calling socket.disconnect()
invokes destroy()
which has this comment in the source:
/**
* Called upon forced client/server side disconnections,
* this method ensures the manager stops tracking us and
* that reconnections don't get triggered for this.
*
* @private
*/
To Reproduce
Please fill the following code example:
Socket.IO server version: 3
Server
import { Server } from "socket.io";
const io = new Server(3000, {});
io.on("connection", (socket) => {
console.log(`connect ${socket.id}`);
socket.on("disconnect", () => {
console.log(`disconnect ${socket.id}`);
});
});
Socket.IO client version: 3
Client
import { io } from "socket.io-client";
const socket = io("ws://localhost:3000/", {});
socket.on("connect", () => {
console.log(`connect ${socket.id}`);
socket.disconnect(); // this does not cause a reconnect
});
socket.on("disconnect", () => {
console.log("disconnect");
});
Expected behavior
The docs should state that this case does not cause a reconnect
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working