Socket disconnect event doesn't always fire

オープン
#5,246 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
28/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
javascript, react-native

調査の方向性

リポジトリのファイルやテストは指定されておらず、報告には再現手順もありません。まず、提供された Socket.IO のクライアント/サーバー構成を iOS 18 で再現し、その後、古いソケットに関係する切断および接続状態の挙動を追跡してください。原因を特定し、回帰テストを追加するか、確認された制限事項を明確に文書化できれば完了です。

索引モデルが issue の本文から書いたものです。

説明

to triage

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.

主要言語
TypeScript
スター
63.2k
フォーク
10.2k
平均マージ
6日 4時間
マージ済み PR(30日)
6

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

socketio/socket.io のほかの issue

socketio/socket.io の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。