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

Missing messages after reopening an existing session #2346

Open
manfe opened this issue Sep 21, 2024 · 0 comments
Open

Missing messages after reopening an existing session #2346

manfe opened this issue Sep 21, 2024 · 0 comments
Labels
bug Something isn't working needs triage

Comments

@manfe
Copy link

manfe commented Sep 21, 2024

Description

Some events are missing, looks like a race condition issue. I've tested with 1 business account, 1 personal account and another 2 numbers (these 2 numbers didn't triggered this issue). It's not clear when this happen, but it's happening!

Environment

  • WPPConnect version(s): 1.34.1
  • WA-JS version(s): 3.10.1
  • Browser: Chrome Version 128.0.6613.138 (Official Build) (arm64)
  • OS: Mac OS
  • Node version: v18.19.0
  • WhatsApp version: 2.3000.1015690181
  • MultiDevice (BETA): yes

Steps to Reproduce

create a regular session, my code:

create({
  session: "test",
  headless: false,
  devtools: true,
  statusFind: (statusSession, session) => {
    // return: isLogged || notLogged || browserClose || qrReadSuccess || qrReadFail || autocloseCalled || desconnectedMobile || deleteToken
    console.log("Status Session: ", statusSession);
    // create session wss return "serverClose" case server for close
    console.log("Session name: ", session);
  },
})
  .then((client) => start(client))
  .catch((error) => console.log(error));

function start(client: Whatsapp) {
  client.getWAVersion().then((version) => {
    console.log("WA Version: ", version);
  });

  client.onAnyMessage((message) => {
    console.log("New Message: ", message.body);
  });

  client.listChats().then((chats) => {
    console.log("chats: ", chats.length);
  });
}

After having a existing session and connected, terminate the process and send 15 messages and then run the process again to start receiving the messages while it was disconnected.

When I sent 9 messages, in this case, first 1-4 messages normally are lost.

In this case, messages with body 1, 2, 3 were lost

debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  4
debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  5
debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  6
debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  7
debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  8
debug:    [manfe:client] Emitting onAnyMessage event (1 registered)
New Message:  9

So I started debugging and I noticed that listener.layer.js is being injected/called after WA.js is already emiting some events for `u.MsgStore.on("add", (e) => {})

But if I add a console.log to the WA.js inside the function when the add is emitted I see the missing messages as isNewMsg.

@manfe manfe added bug Something isn't working needs triage labels Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

1 participant