fix sending to address where the domain does not have an mx record (but where we should connect directly to the host, or follow cname records)

such deliveries would fail because a canceled "context" was reused, so the dns
lookups would fail.

the tests didn't catch it before because they ignored their context parameters.
This commit is contained in:
Mechiel Lukkien
2023-04-24 10:34:19 +02:00
parent 1f4df30019
commit 74dab5fc39
2 changed files with 33 additions and 0 deletions

View File

@ -658,7 +658,10 @@ func gatherHosts(resolver dns.Resolver, m Msg, cid int64, qlog *mlog.Log) (hosts
}
// No MX record. First attempt CNAME lookup. ../rfc/5321:3838 ../rfc/3974:197
ctx, cancel = context.WithTimeout(cidctx, 30*time.Second)
defer cancel()
cname, err := resolver.LookupCNAME(ctx, effectiveDomain.ASCII+".")
cancel()
if err != nil && !dns.IsNotFound(err) {
return nil, effectiveDomain, false, fmt.Errorf("%w: cname lookup for %s: %v", errDNS, effectiveDomain, err)
}