You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "finalchild (via GitHub)" <gi...@apache.org> on 2026/10/08 15:11:28 UTC

[PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

finalchild opened a new pull request, #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479

   ## Summary
   
   - Resolve contact-point hostnames through the operating system resolver with `dns.lookup(name, { all: true })`.
   - Preserve every IPv4 and IPv6 result and the configured contact-point port.
   - Add regression coverage for multiple addresses, both address families, lookup failures, empty results, custom ports, and re-resolution.
   
   ## Motivation
   
   The current implementation uses `dns.resolve4()` and `dns.resolve6()`, which query DNS through c-ares rather than following the operating system's complete name-resolution policy. This can bypass hosts files, NSS, Windows name-resolution policy, VPN and split-DNS configuration, and resolvers such as Tailscale MagicDNS.
   
   The direct-DNS implementation was introduced in #147 when this driver supported Node.js 0.10. The driver now requires Node.js 20 or newer, where `dns.lookup()` supports `{ all: true }`, so using the system resolver no longer requires sacrificing multi-address discovery.
   
   This also follows the approach used by other official Cassandra drivers:
   
   - Java resolves all addresses with `InetAddress.getAllByName()` in `AddressUtils.extract()`.
   - Python resolves contact points with `socket.getaddrinfo(..., AF_UNSPEC, SOCK_STREAM)`.
   - C++ uses `uv_getaddrinfo()` with `AF_UNSPEC` and iterates every result.
   
   ## Verification
   
   - Full unit suite on Node.js 22: 1,351 passing, 1 pending
   - Focused control-connection tests on Node.js 20, 22, and 24: 19 passing on each
   - ESLint passes for both modified files
   - `git diff --check` passes
   
   ## References
   
   - Jira: https://issues.apache.org/jira/browse/CASSNODEJS-16
   - Original resolver PR: https://github.com/apache/cassandra-nodejs-driver/pull/147
   - Node.js DNS documentation: https://nodejs.org/api/dns.html#dnslookuphostname-options-callback
   - Java driver: https://github.com/apache/cassandra-java-driver/blob/trunk/core/src/main/java/com/datastax/oss/driver/internal/core/util/AddressUtils.java
   - Python driver: https://github.com/apache/cassandra-python-driver/blob/trunk/cassandra/cluster.py
   - C++ driver: https://github.com/apache/cassandra-cpp-driver/blob/trunk/src/resolver.hpp


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "finalchild (via GitHub)" <gi...@apache.org>.
finalchild commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4222055430


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });
+      return addresses.map(({address, family}) => ({address, isIPv6: family === 6}));

Review Comment:
   according to node docs family is either 4 or 6. so `family === 6` looks correct.



##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });
+      return addresses.map(({address, family}) => ({address, isIPv6: family === 6}));

Review Comment:
   according to node docs, family is either 4 or 6. so `family === 6` looks correct.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "SiyaoIsHiding (via GitHub)" <gi...@apache.org>.
SiyaoIsHiding commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4275287519


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });
+      return addresses.map(({address, family}) => ({address, isIPv6: family === 6}));

Review Comment:
   agree



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "finalchild (via GitHub)" <gi...@apache.org>.
finalchild commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4222055430


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });
+      return addresses.map(({address, family}) => ({address, isIPv6: family === 6}));

Review Comment:
   according to node docs, family is either 4 or 6. so `family === 6` looks correct. (no other strange unknown families of addresses exist)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "SiyaoIsHiding (via GitHub)" <gi...@apache.org>.
SiyaoIsHiding commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4275320774


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   This doesn't matter



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "finalchild (via GitHub)" <gi...@apache.org>.
finalchild commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4221940454


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   Not completely sure. Feel free to edit my PR if this is desirable on the driver's code style.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4221331484


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   `dns.lookup()` result order can be affected by Node's default result order (e.g., via `dns.setDefaultResultOrder('ipv4first')`), which may undermine the PR goal of following OS/system resolver policy for address preference. Consider passing `verbatim: true` (i.e., `{ all: true, verbatim: true }`) so the driver always uses the OS-provided ordering regardless of process-wide Node settings. Tests that assert the options object would need to be updated accordingly.



##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   When the system resolver returns an empty array, `addresses.map(...)` allocates a new empty array rather than reusing `utils.emptyArray` (which is returned on error). Consider returning `utils.emptyArray` when `addresses.length === 0` to keep return values consistent and avoid an unnecessary allocation in this hot path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "SiyaoIsHiding (via GitHub)" <gi...@apache.org>.
SiyaoIsHiding merged PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "finalchild (via GitHub)" <gi...@apache.org>.
finalchild commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4221917589


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   I think this PR's scope does not include deciding that we should ignore `setDefaultResultOrder`.
   
   https://nodejs.org/api/dns.html#dnslookuphostname-options-callback
   
   Starting from Node 17, verbatim defaults to true and Copilot is right about `setDefaultResultOrder` being able to override the default.
   
   === node docs ===
   
   verbatim <boolean>
   
   When true, the callback receives IPv4 and IPv6 addresses in the order the DNS resolver returned them. When false, IPv4 addresses are placed before IPv6 addresses. This option will be deprecated in favor of order. When both are specified, order has higher precedence. New code should only use order. Default: true (addresses are not reordered). Default value is configurable using [dns.setDefaultResultOrder()](https://nodejs.org/api/dns.html#dnssetdefaultresultorderorder) or [--dns-result-order](https://nodejs.org/api/cli.html#--dns-result-orderorder).



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org


Re: [PR] CASSNODEJS-16: Use system resolver for contact points [cassandra-nodejs-driver]

Posted by "finalchild (via GitHub)" <gi...@apache.org>.
finalchild commented on code in PR #479:
URL: https://github.com/apache/cassandra-nodejs-driver/pull/479#discussion_r4221940454


##########
lib/control-connection.js:
##########
@@ -895,40 +895,21 @@ class ControlConnection extends events.EventEmitter {
   }
 
   /**
-   * Uses the DNS protocol to resolve a IPv4 and IPv6 addresses (A and AAAA records) for the hostname.
+   * Uses the operating system resolver to resolve all IPv4 and IPv6 addresses for the hostname.
    * It returns an Array of addresses that can be empty and logs the error.
    * @private
    * @param name
    */
   async _resolveAll(name) {
-    const addresses = [];
-    const resolve4 = util.promisify(dns.resolve4);
-    const resolve6 = util.promisify(dns.resolve6);
     const lookup = util.promisify(dns.lookup);
 
-    // Ignore errors for resolve calls
-    const ipv4Promise = resolve4(name).catch(() => {}).then(r => r || utils.emptyArray);
-    const ipv6Promise = resolve6(name).catch(() => {}).then(r => r || utils.emptyArray);
-
-    let arr;
-    arr = await ipv4Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: false}));
-
-    arr = await ipv6Promise;
-    arr.forEach(address => addresses.push({address, isIPv6: true}));
-
-    if (addresses.length === 0) {
-      // In case dns.resolve*() methods don't yield a valid address for the host name
-      // Use system call getaddrinfo() that might resolve according to host system definitions
-      try {
-        arr = await lookup(name, { all: true });
-        arr.forEach(({address, family}) => addresses.push({address, isIPv6: family === 6}));
-      } catch (err) {
-        this.log('error', `Host with name ${name} could not be resolved`, err);
-      }
+    try {
+      const addresses = await lookup(name, { all: true });

Review Comment:
   Not completely sure. Feel free to edit my PR if this is needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org