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

Docs for 'disconnect' event are wrong #1443

Closed
vzhou842 opened this issue Feb 12, 2021 · 2 comments
Closed

Docs for 'disconnect' event are wrong #1443

vzhou842 opened this issue Feb 12, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@vzhou842
Copy link

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

@vzhou842 vzhou842 added the bug Something isn't working label Feb 12, 2021
@vzhou842
Copy link
Author

related: socketio/socket.io#3802

darrachequesne added a commit to socketio/socket.io-website that referenced this issue Feb 13, 2021
There are two cases (and not one) where the client will not try to
reconnect automatically.

Related: socketio/socket.io-client#1443
@darrachequesne
Copy link
Member

You are absolutely right, the documentation was not correct. I've fixed it: https://socket.io/docs/v3/client-api/index.html#Event-%E2%80%98disconnect%E2%80%99

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants