Baileys icon indicating copy to clipboard operation
Baileys copied to clipboard

[BUG] When sending message

Open davicolet opened this issue 1 year ago • 33 comments

Hello, I'm having this error when trying to send messages to groups.

Failed to decrypt message with any known session... Session error:MessageCounterError: Key used already or never filled MessageCounterError: Key used already or never filled at SessionCipher.doDecryptWhisperMessage (/home/-/-/node_modules/libsignal/src/session_cipher.js:236:19)

I've tried to rescan the session and it follows.

I'm using useMultiFileAuthState('...') as stated in the documentation

would anyone know what could be causing this?

davicolet avatar Jun 06 '23 01:06 davicolet

can you share with us how you initialize the socket? https://github.com/WhiskeySockets/Baileys/blob/534b1ea778152fa77bee47da291e1f3f5c153091/Example/example.ts#L40

andresayac avatar Jun 06 '23 12:06 andresayac

Of course, I'm using it that way:

socketConfig = {
    defaultQueryTimeoutMs: undefined,
    printQRInTerminal: false,
    browser: ['Dashboard WPP', '', '3.0'],
    logger: pino({
        level: 'silent',
    }),
    generateHighQualityLinkPreview: true,
}

...

const { state, saveCreds } = await useMultiFileAuthState('sessiondata/' + this.key + '/')
this.authState = { state: state, saveCreds: saveCreds, keys: makeCacheableSignalKeyStore(state.keys) }
this.socketConfig.auth = this.authState.state
this.instance.sock = makeWASocket(this.socketConfig)

davicolet avatar Jun 06 '23 12:06 davicolet

try to modify as in the example with respect to Auth in this way has not generated me error

andresayac avatar Jun 06 '23 12:06 andresayac

try to modify as in the example with respect to Auth in this way has not generated me error

andresayac avatar Jun 06 '23 12:06 andresayac

You catch the error when you are trying to send the message. For example: await sock.sendMessage(id, { text: 'hola' });

Cristopher8049 avatar Jun 10 '23 00:06 Cristopher8049

In some whatsapp works perfectly, but in others when trying to send to groups this error occurs and ends up restarting the session:

Failed to decrypt message with any known session...
Session error:Error: Bad MAC Error: Bad MAC
    at Object.verifyMAC (/home/-/node_modules/libsignal/src/crypto.js:87:15)
    at SessionCipher.doDecryptWhisperMessage (/home/-/node_modules/libsignal/src/session_cipher.js:250:16)
    at async SessionCipher.decryptWithSessions (/home/-/node_modules/libsignal/src/session_cipher.js:147:29)
    at async Object.5511971032330.0 [as awaitable] (/home/-/node_modules/libsignal/src/session_cipher.js:171:28)
    at async _asyncQueueExecutor (/home/-/node_modules/libsignal/src/queue_job.js:20:29)
Failed to decrypt message with any known session...
Session error:Error: Bad MAC Error: Bad MAC
    at Object.verifyMAC (/home/-/node_modules/libsignal/src/crypto.js:87:15)
    at SessionCipher.doDecryptWhisperMessage (/home/-/node_modules/libsignal/src/session_cipher.js:250:16)
    at async SessionCipher.decryptWithSessions (/home/-/node_modules/libsignal/src/session_cipher.js:147:29)
    at async Object.5511971032330.0 [as awaitable] (/home/-/node_modules/libsignal/src/session_cipher.js:171:28)
    at async _asyncQueueExecutor (/home/-/node_modules/libsignal/src/queue_job.js:20:29)
Failed to decrypt message with any known session...
Session error:Error: Bad MAC Error: Bad MAC
    at Object.verifyMAC (/home/-/node_modules/libsignal/src/crypto.js:87:15)
    at SessionCipher.doDecryptWhisperMessage (/home/-/node_modules/libsignal/src/session_cipher.js:250:16)
    at async SessionCipher.decryptWithSessions (/home/-/node_modules/libsignal/src/session_cipher.js:147:29)
    at async Object.5511971032330.0 [as awaitable] (/home/-/node_modules/libsignal/src/session_cipher.js:171:28)
    at async _asyncQueueExecutor (/home/-/node_modules/libsignal/src/queue_job.js:20:29)
Failed to decrypt message with any known session...
Session error:Error: Bad MAC Error: Bad MAC
    at Object.verifyMAC (/home/-/node_modules/libsignal/src/crypto.js:87:15)
    at SessionCipher.doDecryptWhisperMessage (/home/-/node_modules/libsignal/src/session_cipher.js:250:16)
    at async SessionCipher.decryptWithSessions (/home/-/node_modules/libsignal/src/session_cipher.js:147:29)
    at async Object.5511971032330.0 [as awaitable] (/home/-/node_modules/libsignal/src/session_cipher.js:171:28)
    at async _asyncQueueExecutor (/home/-/node_modules/libsignal/src/queue_job.js:20:29)
Failed to decrypt message with any known session...

Another error occurring, I don't know if this error is causing the aforementioned one. But some groups timed out, even whatsapp trying to fire being superadmin of the group

[svqlcyjduprwkm] ERRO AO ENVIAR MENSAGEM NO GRUPO -> [email protected] Error: Timed Out
    at /home/-/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:159:32
    at runNextTicks (node:internal/process/task_queues:61:5)
    at listOnTimeout (node:internal/timers:528:9)
    at processTimers (node:internal/timers:502:7) {
  data: {
    stack: 'Error\n' +
      '    at promiseTimeout (/home/-/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:154:19)\n' +
      '    at sendRawMessage (/home/-/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:54:42)\n' +
      '    at sendNode (/home/-/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:70:16)\n' +
      '    at /home/-/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:431:19\n' +
      '    at runMicrotasks (<anonymous>)\n' +
      '    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
      '    at async Object.transaction (/home/-/node_modules/@whiskeysockets/baileys/lib/Utils/auth-utils.js:135:26)\n' +
      '    at async relayMessage (/home/-/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:276:9)\n' +
      '    at async Object.sendMessage (/home/-/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:637:17)\n' +
      '    at async /home/-/src/api/class/instance.js:986:20'
  },
  isBoom: true,
  isServer: false,
  output: {
    statusCode: 408,
    payload: {
      statusCode: 408,
      error: 'Request Time-out',
      message: 'Timed Out'
    },
    headers: {}
  }
}

davicolet avatar Jun 10 '23 17:06 davicolet

I'm facing the same problem, any solution yet?

davigasperin avatar Jul 27 '23 13:07 davigasperin

I have same error... Error: Timed Out at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:136:32 { data: { stack: 'Error\n' + ' at promiseTimeout (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:131:19)\n' + ' at waitForMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:114:53)\n' + ' at query (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:136:22)\n' + ' at groupQuery (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/groups.js:12:55)\n' + ' at groupMetadata (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/groups.js:22:30)\n' + ' at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:288:47\n' + ' at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:291:23\n' + ' at Object.transaction (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/auth-utils.js:136:32)\n' + ' at relayMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:278:30)\n' + ' at Object.sendMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:648:23)\n' + ' at async SendWhatsAppMessage (/home/deploy/whats/backend/dist/services/WbotServices/SendWhatsAppMessage.js:58:29)\n' + ' at async store (/home/deploy/whats/backend/dist/controllers/MessageController.js:54:9)' }, isBoom: true, isServer: false, output: { statusCode: 408, payload: { statusCode: 408, error: 'Request Time-out', message: 'Timed Out' }, headers: {} }

OBS: My project create in database 2 contacts, one contacts with "-" another Contacts whitout "-" See:

whats=# select * from "Contacts" where name like 'Amap%'; id | name | number | profilePicUrl | createdAt | updatedAt | email | isGroup | companyId -------+------------------+-------------------------+--------------------------------------------+----------------------------+----------------------------+-------+---------+---------- 1757 | Amapxxxxxxx | 5537###-xxx103 | https://xxxxxxx/nopicture.png | 2023-01-19 23:59:33.42+01 | 2023-01-19 23:59:33.42+01 | | t | 2 17495 | Amapxxxxxxx | 5537###xxx103 | https://xxxxxxx/nopicture.png | 2023-07-31 18:20:41.528+02 | 2023-07-31 18:20:41.528+02 | | t | 2

In contact whitout "-" I dont send any messages and receive error But i read all messages. In Contact have "-" I send messages but dont read any messages.

lanaparadinha avatar Jul 31 '23 16:07 lanaparadinha

Same error

jefaokpta avatar Sep 29 '23 01:09 jefaokpta

Is there a solution for this problem?

wcpumarega avatar Oct 31 '23 11:10 wcpumarega

Hello, guys. I'm experiencing the same error. Has anyone been able to find a solution?

current-app-1  | Failed to decrypt message with any known session...
current-app-1  | Session error:Error: Bad MAC Error: Bad MAC
current-app-1  |     at Object.verifyMAC (/home/node/app/node_modules/super-libsignal/src/crypto.js:87:15)
current-app-1  |     at SessionCipher.doDecryptWhisperMessage (/home/node/app/node_modules/super-libsignal/src/session_cipher.js:250:16)
current-app-1  |     at async SessionCipher.decryptWithSessions (/home/node/app/node_modules/super-libsignal/src/session_cipher.js:147:29)
current-app-1  |     at async 5545920012998:61.0 [as awaitable] (/home/node/app/node_modules/super-libsignal/src/session_cipher.js:171:28)
current-app-1  |     at async _asyncQueueExecutor (/home/node/app/node_modules/super-libsignal/src/queue_job.js:20:29)

krugerrgabriel avatar Nov 21 '23 14:11 krugerrgabriel

I have same error... Error: Timed Out at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:136:32 { data: { stack: 'Error\n' + ' at promiseTimeout (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/generics.js:131:19)\n' + ' at waitForMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:114:53)\n' + ' at query (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/socket.js:136:22)\n' + ' at groupQuery (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/groups.js:12:55)\n' + ' at groupMetadata (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/groups.js:22:30)\n' + ' at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:288:47\n' + ' at /home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:291:23\n' + ' at Object.transaction (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Utils/auth-utils.js:136:32)\n' + ' at relayMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:278:30)\n' + ' at Object.sendMessage (/home/deploy/whats/backend/node_modules/@whiskeysockets/baileys/lib/Socket/messages-send.js:648:23)\n' + ' at async SendWhatsAppMessage (/home/deploy/whats/backend/dist/services/WbotServices/SendWhatsAppMessage.js:58:29)\n' + ' at async store (/home/deploy/whats/backend/dist/controllers/MessageController.js:54:9)' }, isBoom: true, isServer: false, output: { statusCode: 408, payload: { statusCode: 408, error: 'Request Time-out', message: 'Timed Out' }, headers: {} }

OBS: My project create in database 2 contacts, one contacts with "-" another Contacts whitout "-" See:

whats=# select * from "Contacts" where name like 'Amap%'; id | name | number | profilePicUrl | createdAt | updatedAt | email | isGroup | companyId -------+------------------+-------------------------+--------------------------------------------+----------------------------+----------------------------+-------+---------+---------- 1757 | Amapxxxxxxx | 5537###-xxx103 | https://xxxxxxx/nopicture.png | 2023-01-19 23:59:33.42+01 | 2023-01-19 23:59:33.42+01 | | t | 2 17495 | Amapxxxxxxx | 5537###xxx103 | https://xxxxxxx/nopicture.png | 2023-07-31 18:20:41.528+02 | 2023-07-31 18:20:41.528+02 | | t | 2

In contact whitout "-" I dont send any messages and receive error But i read all messages. In Contact have "-" I send messages but dont read any messages.

looks like a baileys bug, I've never gotten that error code except for the 500 error code

rizxyu avatar Dec 17 '23 05:12 rizxyu

Using just like @davicolet configs and recurrently getting "Timed Out" This property config defaultQueryTimeoutMs: undefined, was also recommended on Baileys Discord Group, but unfortunately doesn't solve the problem. I'm also getting BAD MAC error, someone said that the "actual workaround" is to restart the whatsapp connection every 6 hours.. But didn't worked for me as well.. Is it there any solution yet?

rayanchemin avatar Dec 18 '23 14:12 rayanchemin

I have the same error here

raphaelvserafim avatar Jan 10 '24 00:01 raphaelvserafim

Também estou com o mesmo problema, alguma solução?

ianvictor avatar Jan 20 '24 17:01 ianvictor

Também estou com o mesmo problema.

FlavioCoutinhoGO avatar Jan 24 '24 18:01 FlavioCoutinhoGO

+1

4relial avatar Jan 27 '24 02:01 4relial

+1

roysG avatar Mar 25 '24 21:03 roysG

+1

izaias-nascimento avatar Apr 03 '24 12:04 izaias-nascimento

Bom dia, alguma solução?

hiagodeoliveiratv avatar May 05 '24 10:05 hiagodeoliveiratv

A solução é fazer tratamento em grupos. Não é bug do bayleis.

The solution is make processing in groups. not bug of bayleis.

lanaparadinha avatar May 08 '24 18:05 lanaparadinha

Com certeza é um bug do Baileys...

Esse erro fica aparecendo porque o Baileys não é capaz de lidar com algo e também não mostra como tratar isso... definitivamente não é um comportamento esperado em nenhum software.

FlavioCoutinhoGO avatar May 13 '24 21:05 FlavioCoutinhoGO

A solução é fazer tratamento em grupos. Não é bug do bayleis.

The solution is make processing in groups. not bug of bayleis.

Qual foi a solução para você?

joaosouz4dev avatar Jul 02 '24 17:07 joaosouz4dev

bad decryption errors are due to some mismanagement in our libsignal, will look into them all

purpshell avatar Jul 03 '24 07:07 purpshell