pedroslopez / whatsapp-web.js

A WhatsApp client library for NodeJS that connects through the WhatsApp Web browser app
https://wwebjs.dev
Apache License 2.0
14.53k stars 3.46k forks source link

Client.getState() returning with state connected but in reality it's not connected. Session Falling. #2125

Open samuelfaj opened 1 year ago

samuelfaj commented 1 year ago

Is there an existing issue for this?

Describe the bug

I have an interval function in my robot that checks the connection status every 10 seconds using the setInterval method. The code is as follows:

checkInterval = setInterval(async () => {
    const state = await Robot.client.getState();

    console.log('Status do Robô:', state)

    if(state != WAState.CONNECTED && state != WAState.OPENING && state != WAState.PAIRING){
        await Robot.fallDown('Status do Robô: ' + state);
    }
}, 10 * 1000);

The code appears to be working fine as it consistently shows that the robot is connected and able to send messages. However, I have noticed that sometimes the robot loses its connection with the WhatsApp server, which I can see from the lack of ACK responses. Even though the robot continues to display a connected status, it is actually disconnected and unable to really send or receive messages.

When this happens, I have to restart the robot, and It asks to scan the QR Code again to reestablish the connection. It seems that something happens to the session during these intermittent connection drops.

Expected behavior

It should keep the connection opened, or client.getState() should display the right state.

Steps to Reproduce the Bug or Issue

Just stay connected for a while

Relevant Code

No response

Browser Type

Google Chrome

WhatsApp Account Type

WhatsApp Business

Does your WhatsApp account have multidevice enabled?

Yes, I am using Multi Device

Environment

Ubuntu 22.04 Node.js: 16.16 whatsapp-web.js: ^1.19.5 Phone: Android WhatsApp: 2.2314.7

Additional context

No response

kikemarto commented 1 year ago

Same here

kikemarto commented 1 year ago

I don't lose the session but if that happens to me what do you explain, any solution?

HiramNeto commented 1 year ago

Exact same thing here, also change_state neither disconnected events are never triggered. I saw that sometimes the change state event is triggered after hours of disconnection, but by checking the state changes they indicate a lost connection for only a couple of seconds, despite the connection to send messages or get messages info is not working, neither before or after those state_change events... The only thing that makes everything comes back to normal is to reset the whole application, and everytime that this happen I need to rescan the qr code again...

mbnaj commented 9 months ago

any solution for this issue?

alechkos commented 7 months ago

@samuelfaj Is still relevant?

juancruzsosagab commented 6 months ago

This is happening to us too, is there any way to solve this?It's very important for us! Thanks!

FrancoAlfano commented 6 months ago

We are dealing with this issue as well!

justoverclockl commented 5 months ago

getstate is definitely broken

rbkayz commented 3 months ago

Any solution here?

matheuspbmarques commented 3 weeks ago

Anywhere find any solution?