Skip to content

Commit

Permalink
Add DNS timeout (#1468)
Browse files Browse the repository at this point in the history
* Add DNS timeout

* Create resolver instance

* Compatibility for Node < 8.3.0

* chore: semicolon
  • Loading branch information
huksley committed Sep 28, 2022
1 parent 0a52eeb commit e091992
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/shared/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ const resolver = (family, hostname, options, callback) => {
return callback(null, []);
}

dns['resolve' + family](hostname, (err, addresses) => {
const resolver = dns.Resolver ? new dns.Resolver(options) : dns;
resolver['resolve' + family](hostname, (err, addresses) => {
if (err) {
switch (err.code) {
case dns.NODATA:
Expand Down
5 changes: 4 additions & 1 deletion lib/smtp-connection/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const shared = require('../shared');
const CONNECTION_TIMEOUT = 2 * 60 * 1000; // how much to wait for the connection to be established
const SOCKET_TIMEOUT = 10 * 60 * 1000; // how much to wait for socket inactivity before disconnecting the client
const GREETING_TIMEOUT = 30 * 1000; // how much to wait after connection is established but SMTP greeting is not receieved
const DNS_TIMEOUT = 30 * 1000; // how much to wait for resolveHostname

/**
* Generates a SMTP connection object
Expand All @@ -30,6 +31,7 @@ const GREETING_TIMEOUT = 30 * 1000; // how much to wait after connection is esta
* * **greetingTimeout** - Time to wait in ms until greeting message is received from the server (defaults to 10000)
* * **connectionTimeout** - how many milliseconds to wait for the connection to establish
* * **socketTimeout** - Time of inactivity until the connection is closed (defaults to 1 hour)
* * **dnsTimeout** - Time to wait in ms for the DNS requests to be resolved (defaults to 30 seconds)
* * **lmtp** - if true, uses LMTP instead of SMTP protocol
* * **logger** - bunyan compatible logger interface
* * **debug** - if true pass SMTP traffic to the logger
Expand Down Expand Up @@ -220,7 +222,8 @@ class SMTPConnection extends EventEmitter {
let opts = {
port: this.port,
host: this.host,
allowInternalNetworkInterfaces: this.allowInternalNetworkInterfaces
allowInternalNetworkInterfaces: this.allowInternalNetworkInterfaces,
timeout: this.options.dnsTimeout || DNS_TIMEOUT
};

if (this.options.localAddress) {
Expand Down

0 comments on commit e091992

Please sign in to comment.