Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Socket.IO stops working randomly until page refresh #5299

Open
vitortoigo opened this issue Feb 18, 2025 · 3 comments
Open

Socket.IO stops working randomly until page refresh #5299

vitortoigo opened this issue Feb 18, 2025 · 3 comments

Comments

@vitortoigo
Copy link

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!

@vitortoigo vitortoigo added the to triage Waiting to be triaged by a member of the team label Feb 18, 2025
@darrachequesne
Copy link
Member

Hi! That's really weird indeed, I guess you aren't able to reproduce it reliably? Does it happen in a given browser? Or after a specific delay? How do you detect it?

@darrachequesne darrachequesne added needs investigation and removed to triage Waiting to be triaged by a member of the team labels Feb 20, 2025
@vitortoigo
Copy link
Author

Hi! That's really weird indeed, I guess you aren't able to reproduce it reliably? Does it happen in a given browser? Or after a specific delay? How do you detect it?

Hi! Yeah, I can't reproduce the error consistently. It happens in any browser, and I believe it occurs after a certain amount of time. My application is a chat, so I'm sending messages normally, but at some point, I try to send a new message, and it just doesn't go through. The only way to make it work again is by refreshing the page.

@darrachequesne
Copy link
Member

Without the ability to reproduce the issue, it will be quite hard to find the cause... We'd need to have access to the internal state of the client when that happens.

Could it simply be a temporary disconnection? Or a missing event listener?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

2 participants