fix: "Media upload failed on all hosts" utilizando proxy by JefersonRamos · Pull Request #2141 · EvolutionAPI/evolution-api · GitHub
Skip to content

fix: "Media upload failed on all hosts" utilizando proxy#2141

Merged
DavidsonGomes merged 2 commits intoEvolutionAPI:mainfrom
JefersonRamos:bugfix/media-upload-failed-on-all-hosts
Oct 29, 2025
Merged

fix: "Media upload failed on all hosts" utilizando proxy#2141
DavidsonGomes merged 2 commits intoEvolutionAPI:mainfrom
JefersonRamos:bugfix/media-upload-failed-on-all-hosts

Conversation

@JefersonRamos
Copy link
Copy Markdown
Contributor

@JefersonRamos JefersonRamos commented Oct 27, 2025

📋 Description

Esse erro acontece porque o Node.js (a partir da versão 18) usa o Undici como implementação nativa de fetch(), e o Undici não aceita mais objetos agent tradicionais (como os criados por https-proxy-agent ou socks-proxy-agent).
Ele espera objetos compatíveis com a interface moderna Dispatcher, que possuem o método dispatch().

Ou seja, o Baileys estava recebendo um tipo de agente incompatível com o novo sistema de rede do Node.

Foi criada uma nova função makeProxyAgentUndici() para gerar agentes de proxy compatíveis com o Undici, mantendo a versão antiga (makeProxyAgent()) inalterada para compatibilidade com bibliotecas como Axios.

A nova função substitui os antigos HttpsProxyAgent e SocksProxyAgent por ProxyAgent da biblioteca undici, garantindo compatibilidade total com o Baileys e com qualquer uso de fetch() moderno.

🔗 Related Issue

Closes #2117

🧪 Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧹 Code cleanup
  • 🔒 Security fix

🧪 Testing

  • Manual testing completed
  • Functionality verified in development environment
  • No breaking changes introduced
  • Tested with different connection types (if applicable)

📸 Screenshots (if applicable)

✅ Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have manually tested my changes thoroughly
  • I have verified the changes work with different scenarios
  • Any dependent changes have been merged and published

📝 Additional Notes

O protocolo socks é automaticamente normalizado para socks5, evitando erro de usuários que informem apenas "socks"

Summary by Sourcery

Introduce Undici-compatible proxy handling by adding makeProxyAgentUndici, updating BaileysStartupService to use it for fetchAgent, and adding undici to dependencies to ensure compatibility with Node.js 18+ native fetch

New Features:

  • Add makeProxyAgentUndici function to create Dispatcher-compatible proxy agents using undici

Bug Fixes:

  • Fix incompatible proxy agents in Baileys with Node.js 18+ native fetch

Enhancements:

  • Normalize 'socks' protocol to 'socks5' when constructing proxy URLs

Build:

  • Add undici dependency to enable ProxyAgent

…ici como implementação nativa de fetch(), e o Undici não aceita mais objetos agent tradicionais (como os criados por https-proxy-agent ou socks-proxy-agent).

Ele espera objetos compatíveis com a interface moderna Dispatcher, que possuem o método dispatch().

Ou seja, o Baileys estava recebendo um tipo de agente incompatível com o novo sistema de rede do Node.

Foi criada uma nova função makeProxyAgentUndici() para gerar agentes de proxy compatíveis com o Undici, mantendo a versão antiga (makeProxyAgent()) inalterada para compatibilidade com bibliotecas como Axios.

A nova função substitui os antigos HttpsProxyAgent e SocksProxyAgent por ProxyAgent da biblioteca undici, garantindo compatibilidade total com o Baileys e com qualquer uso de fetch() moderno.
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented Oct 27, 2025

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `src/utils/makeProxyAgent.ts:58` </location>
<code_context>
+    proxyUrl = proxy
+  } else {
+    const { host, password, port, protocol: proto, username } = proxy
+    protocol = proto.replace(':', '')
+
+    if (protocol === 'socks') {
</code_context>

<issue_to_address>
**issue:** Potential issue if 'proto' is undefined in Proxy object.

Add a check or default value for 'proto' to prevent errors when it is undefined.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/utils/makeProxyAgent.ts Outdated
@JefersonRamos JefersonRamos changed the title Esse erro acontece porque o Node.js (a partir da versão 18) usa o Und… "Media upload failed on all hosts" utilizando proxy Oct 27, 2025
@JefersonRamos JefersonRamos changed the title "Media upload failed on all hosts" utilizando proxy fix: "Media upload failed on all hosts" utilizando proxy Oct 27, 2025
@renansko-vilela
Copy link
Copy Markdown

@suissa quando tempo até a verificação da PR?

@MattCarneiro
Copy link
Copy Markdown

MattCarneiro commented Oct 29, 2025

EDIT: aqui deu certo. mt obrigado

@DavidsonGomes DavidsonGomes merged commit df20c5f into EvolutionAPI:main Oct 29, 2025
1 check passed
@BezzerraJr
Copy link
Copy Markdown

Captura de tela 2025-11-14 185912

Aqui da esse erro quando envia um link com proxy. Sem essa atualização vai normal. Sem o proxy vai também

@luispimenta
Copy link
Copy Markdown

@JefersonRamos isso ja esta na versão 2.3.6? ou vai ser na próxima?

@renansko-vilela
Copy link
Copy Markdown

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

Successfully merging this pull request may close these issues.

Chatwoot e Evolution 2.3.6 - Envio de áudio do Chatwoot para Evolution dá erro!

6 participants