From 13a3faa1faeeaab6a5b218488e715e4e7c705531 Mon Sep 17 00:00:00 2001
From: Yoshiki Kurihara <yosyos0306@gmail.com>
Date: Sat, 22 Jan 2022 08:53:53 +0900
Subject: [PATCH] lib: fix consistency of methods that emit warnings

PR-URL: https://github.com/nodejs/node/pull/41249
Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
---
 lib/internal/dns/utils.js | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/lib/internal/dns/utils.js b/lib/internal/dns/utils.js
index 8fd5e2018f2d9c..fa7e19c784789c 100644
--- a/lib/internal/dns/utils.js
+++ b/lib/internal/dns/utils.js
@@ -178,18 +178,16 @@ function validateHints(hints) {
 }
 
 let invalidHostnameWarningEmitted = false;
-
 function emitInvalidHostnameWarning(hostname) {
-  if (invalidHostnameWarningEmitted) {
-    return;
+  if (!invalidHostnameWarningEmitted) {
+    process.emitWarning(
+      `The provided hostname "${hostname}" is not a valid ` +
+      'hostname, and is supported in the dns module solely for compatibility.',
+      'DeprecationWarning',
+      'DEP0118'
+    );
+    invalidHostnameWarningEmitted = true;
   }
-  invalidHostnameWarningEmitted = true;
-  process.emitWarning(
-    `The provided hostname "${hostname}" is not a valid ` +
-    'hostname, and is supported in the dns module solely for compatibility.',
-    'DeprecationWarning',
-    'DEP0118'
-  );
 }
 
 let dnsOrder = getOptionValue('--dns-result-order') || 'ipv4first';