Skip to content

Old websockets do not seem to be terminated #170

@chongma

Description

@chongma

I am having a strange issue with websockets. I have my websocket server behind an apache httpd 2.4.51 proxy and the sockets keep disconnecting after 30 seconds or so. I am trying to investigate the issue but in the meantime I have installed reconnecting-websockets and it seems to work.

But now I have discovered that the chrome tab eventually runs out of memory and looking into the network tab on chrome reveals that lots of duplicate websockets are being created and they have status "101" whereas sometimes i get one that says status "finished"

Screenshot from 2021-11-20 19-34-34

I am using VueX to try to store a single instance of each reconnecting websocket, essentially like this

function urlProviderAutorespond() {
    return `${process.env.VUE_APP_CT_WS_V1}/websockets/admin/autoreply?access_token=${Vue.prototype.$keycloak.token}`;
}

initialiseWsAutorespond({ state, commit }) {
        if (!state.wsAutorespond) {
            const ws = new ReconnectingWebSocket(urlProviderAutorespond);
            ws.onmessage = (event) => {
                commit('setAutorespond', JSON.parse(event.data));
            };
            ws.onopen = async () => {
                if (state.firstAutorespond) {
                    // fetch some data
                    commit('setFirstAutorespond', false);
                }
                console.log("Autorespond websocket opening...");
            };
            commit('setWsAutorespond', ws);
        }
    }

The issue may be related to the way that the server is terminating the connection but reconnecting-websockets shouldn't create a new one while the old one is still open?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions