- 
                Notifications
    You must be signed in to change notification settings 
- Fork 10.1k
Open
Labels
to triageWaiting to be triaged by a member of the teamWaiting to be triaged by a member of the team
Description
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:

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.
Metadata
Metadata
Assignees
Labels
to triageWaiting to be triaged by a member of the teamWaiting to be triaged by a member of the team