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

Socket disconnect event doesn't always fire #5246

Open
nzapponi opened this issue Nov 29, 2024 · 0 comments
Open

Socket disconnect event doesn't always fire #5246

nzapponi opened this issue Nov 29, 2024 · 0 comments
Labels
to triage Waiting to be triaged by a member of the team

Comments

@nzapponi
Copy link

Describe the bug
We have a React Native app using Socket.io to communicate with our servers.
Some users experience a quirk whereby leaving the app doesn't fire a disconnect event on the server for a very long time (hours).

See screenshot of some of our logs:
Screenshot 2024-11-29 at 23 20 42

This also occurs upon making a io.in([...]).fetchSockets() call: those sockets still look open.

To Reproduce
N/A

Socket.IO server version: 4.8.1

Server

import { Server } from "socket.io";

const io = new SocketServer<
      ClientToServerEvents,
      ServerToClientEvents,
      { [event: string]: (...args: unknown[]) => void },
      SocketData
    >(server, {
      path: "/socket",
      serveClient: false,
      cookie: true,
      adapter: socketIoPubSubTopic
        ?
          createAdapter(socketIoPubSubTopic)
        : undefined,
    });

    if (socketIoPubSubTopic) {
      await io.of("/").adapter.init();
      log.log("Pub/sub subscription initialized for Socket.IO");
    }

    io.on("connection", async (socket) => {
    const userId = socket.data.userId;
    log.log({ userId }, `Socket connected for ${userId}`);

    if (userId) {
      await updateJoinedRooms(userId, socket);
    }

    socket.on("disconnect", () => {
      log.log({ userId }, `Socket disconnected for ${userId}`);
    });
  });

Socket.IO client version: 4.8.1

Client

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

const newSocket: TypedSocket = io(PUBLIC_SOCKET_HOST, {
        auth: !useCookies
          ? {
              token,
            }
          : undefined,
        path:"/socket",
        ackTimeout: 10000,
        retries: 12,
        timeout: 5000,
        reconnectionDelayMax: 5000,
        withCredentials: useCookies,
      });

Expected behavior
To always get the disconnect event firing.

Platform:

  • Device: iPhone 14 Plus
  • OS: iOS 18

Additional context
Add any other context about the problem here.

@nzapponi nzapponi added the to triage Waiting to be triaged by a member of the team label Nov 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
to triage Waiting to be triaged by a member of the team
Projects
None yet
Development

No branches or pull requests

1 participant