Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

problem with setInterval wsp.send('ping') openWebSocket.js #209

Open
paliuca opened this issue Mar 14, 2023 · 1 comment
Open

problem with setInterval wsp.send('ping') openWebSocket.js #209

paliuca opened this issue Mar 14, 2023 · 1 comment

Comments

@paliuca
Copy link

paliuca commented Mar 14, 2023

Hello,
I encountering a problem with this setInterval located at the end of the openWebSocket.js file located in ewelink-api/src/mixins/
setInterval(async () => {
await wsp.send('ping');
}, heartbeat);
The problem is that the send function in the WebSocketAsPromised is trowing an error (when the socket is not opened ) which is not handled in the openWebSocket.js so the node js crashes.
i fixed it by replacing those 3 lines with:

    const intervalID = setInterval(async () => {
        try {
            await wsp.send('ping');
        } catch (error) {
            clearInterval(intervalID);
        }
    }, heartbeat);

Is it possible to to that? or I am doing something wrong.
Thank you

@julynessi
Copy link

Have same problem. Anything that make websocket cannot communicate to coolkit server eg. computer sleep, internet connection lost ... It's always make node app crash .. because no exception handle in openWebSocket.js ..... I can handle this problem without changing the "ewelink-api" module by use "pm2' to run app and if it's crash it's automatic restart. hope this issue fix in the future......in fact before pm2 I try to set heartbeat to maximum of int32 and manage to send ping myself It's not survive, then no ping send at all....but the web socket still send ping (I observed with onSend callback) anyway if you need some solution to handle this problem I prefer "pm2" to run the app and automatic restart if it's crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants