haraka / Haraka

A fast, highly extensible, and event driven SMTP server
https://haraka.github.io
MIT License
5.02k stars 662 forks source link

Outbound mail does not respect /etc/hosts file for A record #1305

Closed fischerman closed 8 years ago

fischerman commented 8 years ago

I'm using haraka in a docker container for inbound mail linked to a dovecot container with LMTP enabled. Every mail is forwarded via LMTP. Docker uses /etc/hosts to set the IP of the linked container. I've set my lmtp.ini accordingly to

host=lmtp
port=24

I can ping lmtp just fine, however haraka can not resolve it:

[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] running send_email
 hooks
[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] Sending mail: 1453
053679833_0_6_3628.d8fee626ccf0
[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] running get_mx hoo
ks
[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] running get_mx hoo
k in queue/lmtp plugin
[INFO] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] hook=get_mx plugin=
queue/lmtp function=hook_get_mx params="example.com" retval=OK msg="[object
 Object]"
[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] Got an MX from Plu
gin: example.com => 0 [object Object]
[INFO] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] Looking up A record
s for: lmtp
[ERROR] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] DNS lookup of lmtp
 failed: Error: queryA ENOTFOUND lmtp
[DEBUG] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] running deferred h
ooks
[INFO] [E1149A5A-A799-4F6C-BC73-5186C940D3B2.1.1] [outbound] Temp failing 145305
3679833_0_6_3628.d8fee626ccf0 for 64 seconds: Tried all MXs

I've noticed that in outbound.js:992 resolve is used which goes to the NS server directly rather then lookup which also checks the hosts

dns.resolve(host, family, function (err, addresses) {
Dexus commented 8 years ago

You can use ENV like in docs as a workaround https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/

smfreegard commented 8 years ago

This is by design. We avoid dns.lookup() because it uses the system resolver which is a blocking system call which means Node has to call it via its internal thread pool for it to work asynchronously and that would hurt our performance.

I would modify queue/lmtp to check process.env for the appropriate value rather than switch it to dns.lookup if you need performance.

msimerson commented 8 years ago

This is by design. We avoid dns.lookup()

Amen! (dns.lookup also has some odd edge cases)