socketio / socketio/socket.io

Socket.IO stops working randomly until page refresh

Open
#5,299 9 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

needs investigation
Dominant language
TypeScript
Stars
63.2k
Forks
10.3k
Avg merge
11d 20h
Merged PRs (30d)
2

Description

Hi, I'm using Socket.IO in a Node.js project, and sometimes the socket connection just stops working. The only way to get it working again is by refreshing the browser page.

I'm using namespaces to separate tenants, and Redis to manage socket IDs. Here is my frontend and backend configuration:

Frontend (Client-side):

export function connectSocketToNamespace(namespace: string): void {
    socket = io(`${import.meta.env.VITE_SERVER_URL}/${namespace}`, {
        auth: {
            token: getAuthToken()
        },
        query: {
            sessionKey: getSession()
        },
        transports: ["websocket"],
        upgrade: false,
        reconnection: true,
        reconnectionAttempts: Infinity,
        reconnectionDelay: 2000,
        reconnectionDelayMax: 10000,
        randomizationFactor: 0.5,
    });
}

Backend (Server-side - AdonisJS):

public boot() {
    if (!this.booted) {
        this.io = new Server(AdonisServer.instance!, {
            maxHttpBufferSize: maxUploadFileSize(),
            pingInterval: 10000,
            pingTimeout: 25000,
            cors: {
                origin: Env.get('CLIENT_URL')
            }
        });

        this.booted = true;

        this.configureNamespaces();
        this.clearOldSockets();
    }
}

There are no errors in the console or server logs, and this issue happens randomly.

Has anyone experienced something similar? Could this be related to the Redis adapter or the namespace handling? Any suggestions on debugging or fixing this issue?

Thanks in advance!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the supplied TypeScript frontend connection configuration and the backend boot configuration, then reproduce the random disconnect while observing namespace, reconnection, and Redis behavior. Done means identifying a reproducible cause and documenting a narrowly scoped fix or diagnostic result; the issue names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, redis, typescript
Domain
backend, networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.