evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

[META] QR Code / Pairing issues — tracking umbrella

Open jpedrodouradoo-cell opened this issue 9 months ago • 87 comments

Meta-issue consolidating all open QR Code / pairing-related reports. Please do not open new QR Code issues — comment here instead.

Known symptoms

  • QR Code never appears, loading forever (/instance/connect returns {"count": 0})
  • QR Code is generated but invalid / expires immediately
  • Connects then drops: stream errored out (code 515) + Pre-key upload timeout (code 408)
  • Android devices cannot read QR while iOS can
  • Pairing code login succeeds but no message events received (401 / device_removed)
  • QR refreshes every 1 minute instead of WhatsApp's native 3 minutes
  • Endpoint /instance/qrcode returns 404 (v2.3.1)
  • Behind Cloudflare / nginx: 504 Gateway Timeout generating QR
  • Behind Coolify / Railway / Docker: QR not generated

Known working workaround (community-sourced, see #2463 for full walkthrough)

Set the following env vars and restart the container:

CACHE_REDIS_ENABLED=false
CACHE_LOCAL_ENABLED=true
DATABASE_SAVE_DATA_CHATS=false
DATABASE_SAVE_DATA_CONTACTS=false
DATABASE_SAVE_DATA_HISTORIC=false
DATABASE_SAVE_DATA_LABELS=false
CONFIG_SESSION_PHONE_VERSION=2.3000.1033773198

Root cause (per community analysis): the server chokes on CPU/RAM when Baileys generates pre-keys at the same time that the Meta history "tsunami" arrives, causing pre-key timeout → stream error 515 → device kick. Redis over Docker network adds latency; disabling history sync and switching to local cache removes the bottleneck.

Scope

This umbrella tracks the infrastructure-level QR/pairing problem. Sub-topics that deserve their own issue:

  • Chatwoot-specific QR regeneration bugs → see #2014 (Chatwoot umbrella)
  • @lid vs @jid in pairing flow → see @lid umbrella

For maintainers

All duplicate QR Code issues are being closed with state_reason: duplicate pointing here. If you want to respond per-user, use this thread as the single source of truth.


This issue was reorganized from the original report ("Não gera QR Code da Instancia") as part of the 2026-04 issue triage. The original reporter (@jpedrodouradoo-cell) and all community contributors remain credited in the comment history.

jpedrodouradoo-cell avatar Feb 20 '26 10:02 jpedrodouradoo-cell

Segue o que eu fiz e solucionou.

a Meta está resetando a conexão SSL de containers Docker hospedados na Hostinger (ASN 47583) quando tentam se conectar ao WhatsApp.

A essência da solução é apenas uma: fazer o container da Evolution API usar o IP real do seu servidor, ignorando a rede virtual interna (NAT) do Docker.

Para contornar o bloqueio da Meta, você precisa fazer duas alterações fundamentais na forma como a Evolution API sobe no seu servidor.

  1. Mudar a rede da Evolution API para o modo Host Isso vai tirar a API da rede isolada e conectá-la diretamente à placa de rede da sua VPS. No seu arquivo docker-compose.yml, você deve adicionar a diretiva network_mode: "host".

  2. Expor as portas do Banco de Dados e Redis Como a API agora vai rodar "fora" da rede do Docker, ela não consegue mais enxergar o PostgreSQL e o Redis pelo nome do container. Você precisa mapear as portas deles para o host (ex: 5432:5432) e mudar a URL de conexão nas variáveis da API para apontar para 127.0.0.1.

O seu docker-compose.yml precisará ficar com essa estrutura: services: evolution-api: image: xxxxx network_mode: "host" # ISSO RESOLVE O BLOQUEIO DA META # ports: <-- APAGUE A SESSÃO DE PORTAS, ELA É IGNORADA NO MODO HOST # - "8080:8080" environment: # Mude o host do banco e redis para 127.0.0.1 - DATABASE_CONNECTION_URI=postgres://usuario:[email protected]:5432/evolution - CACHE_REDIS_URI=redis://127.0.0.1:6379 # ... mantenha o resto das suas variáveis de ambiente ...

postgres: image: postgres:15 ports: - "5432:5432" # Obrigatório para a API conseguir acessar de "fora" da rede docker

redis: image: redis:alpine ports: - "6379:6379" # Obrigatório

Após ajustar o arquivo com as suas senhas e dados corretos, basta recriar os containers:

docker-compose down docker-compose up -d

NiceFeatures avatar Feb 26 '26 00:02 NiceFeatures

Hostinger instance is working again for now (02/03/26) and it's generating the QR code.

lecano avatar Mar 02 '26 15:03 lecano

Fala pessoal Pela Hostinger Consegui resolver so deletando alguns dados da Variáveis de Ambiente

Olhe para a última linha do seu arquivo de configuração: CONFIG_SESSION_PHONE_VERSION=2.3000.1026080446

Aqui está o erro fatal. O WhatsApp atualiza a versão do Web Socket quase semanalmente. Ao chumbar uma versão específica no arquivo de configuração, você engessou a API. Se a Meta (WhatsApp) descontinuar ou alterar a assinatura dessa versão exata, o núcleo da Evolution API tenta conectar, é rejeitado silenciosamente e entra em um loop infinito. É por isso que o botão "Restart" no painel não funciona e o QR Code não aparece: o sistema operacional travou o processo aguardando uma resposta que nunca virá.

Você precisa acessar os arquivos da sua VPS (seja via SSH, FTP, ou pelo painel do Coolify/Portainer se tiver usado um deles para instalar) e alterar o arquivo .env.

Exclua a linha CONFIG_SESSION_PHONE_VERSION=2.3000.1026080446 completamente, ou deixe-a vazia: CONFIG_SESSION_PHONE_VERSION=.

Isso forçará a Evolution API a buscar dinamicamente a versão mais recente e compatível do WhatsApp Web sempre que iniciar.

FredPrestupa avatar Mar 06 '26 00:03 FredPrestupa

Adding this to environments solved the QR generation for me: CONFIG_SESSION_PHONE_VERSION=2.3000.1033893291

because i found in this Baileys issues: https://github.com/WhiskeySockets/Baileys/issues/2370

Willi4amVargas avatar Mar 11 '26 01:03 Willi4amVargas

Incluir essas variáveis e funcionou.

CONFIG_SESSION_PHONE_VERSION = 2.3000.1033773198 NODE_OPTIONS=--dns-result-order=ipv4first

nickbazila avatar Mar 20 '26 18:03 nickbazila

Adjacent — not a fix for QR/pairing failures themselves, but for the post-pairing "ban after 24-48h" pattern that often follows.

Shipped baileys-antiban-evolution today: adapter that adds rate-limiting + session-stability monitoring + device-fingerprint randomization to Evolution's BaileysStartupService at runtime.

https://github.com/kobie3717/baileys-antiban-evolution

Will help if your pairing succeeds but the account dies inside the first week. Won't help if pairing itself fails — that's protocol-level (Baileys upstream). Posting here in case it's adjacent for some people on the thread.

kobie3717 avatar Apr 26 '26 06:04 kobie3717

Working Docker recipe: patching Baileys inside the Evolution image to fix device pairing

The root cause is upstream, not Evolution. WhatsApp changed the companion-registration flow: since ~2026-07-28 the server sends <notification type='companion_reg_refresh'> after the QR scan, which Baileys acks and discards — so pair-success is never emitted and the phone shows "couldn't link device / não foi possível conectar no momento". See Baileys #2737, reproduced independently in whatsmeow, which means it affects every open client, not just Baileys.

Evolution v2.3.7 pins [email protected], and no published Baileys release contains the fix (the handler is absent in rc13, rc14 and master). The fix only exists as unmerged PRs.

I couldn't find any public recipe for replacing Baileys inside the Evolution image, so here is one that works:

FROM evoapicloud/evolution-api:v2.3.7
WORKDIR /evolution

# Alpine is minimal: npm needs git to clone the fork; the package's `prepare` runs tsc.
RUN apk add --no-cache git \
 && npm install --no-audit --no-fund baileys@github:doryani-ai/Baileys#fix/companion-reg-refresh \
 && apk del git

# Optional — only if you use the PAIRING CODE flow (Baileys PR #2602 / issue #2600).
# WhatsApp sends `link_code_companion_reg` in two shapes; the one without the crypto
# fields crashes with Boom('Invalid buffer', 400). This guard skips it.
RUN sed -i "s|const linkCodeCompanionReg = getBinaryNodeChild(node, 'link_code_companion_reg');|&\n                if (!getBinaryNodeChildBuffer(linkCodeCompanionReg, 'primary_identity_pub')) { break; }|" \
      /evolution/node_modules/baileys/lib/Socket/messages-recv.js

Build it, point your compose at the resulting image, and recreate only the evolution-api service.

Result: Baileys 7.0.0-rc14, QR pairing works again (state=open, session stable).

Two things worth knowing

  1. Security bonus. rc14 also clears CVE-2026-48063 (Critical — messages.upsert / history-sync spoofing and app-state corruption), which affects < rc12. Anyone still on v2.3.7 is exposed regardless of the pairing issue.
  2. Already-paired sessions keep working. This only breaks linking a new device, so it's an onboarding blocker rather than a runtime one.

⚠️ This depends on an unmerged upstream PR — treat it as tracked maintenance debt, not a permanent fix. The real fix is PR #2765 landing upstream and Evolution bumping Baileys.

cloviscoli avatar Sep 10 '26 19:09 cloviscoli