Skip to content

Commit

Permalink
dgram: skip dns lookup for IPs
Browse files Browse the repository at this point in the history
Previously, we would call dns.lookup even for IP addresses
in Socket#connect. This now skips that to improve performance.

Fixes: nodejs#39468
  • Loading branch information
evanlucas committed Jul 20, 2021
1 parent ad5dc4c commit ed6bfef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/dgram.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const {
newHandle,
} = require('internal/dgram');
const { guessHandleType } = internalBinding('util');
const { isIP } = require('internal/net');
const {
ERR_INVALID_ARG_TYPE,
ERR_MISSING_ARGS,
Expand Down Expand Up @@ -403,6 +404,19 @@ function _connect(port, address, callback) {
if (callback)
this.once('connect', callback);

// If host is an IP, skip performing a lookup.
const addressType = isIP(address);
if (addressType) {
defaultTriggerAsyncIdScope(this[async_id_symbol], process.nextTick, () => {
defaultTriggerAsyncIdScope(
this[async_id_symbol],
doConnect,
null, this, address, address, port, callback
);
});
return;
}

const afterDns = (ex, ip) => {
defaultTriggerAsyncIdScope(
this[async_id_symbol],
Expand Down

0 comments on commit ed6bfef

Please sign in to comment.