@@ -4,6 +4,9 @@ const dns = require('dns');
44const async = require ( 'async' ) ;
55const debug = require ( 'debug' ) ( 'redns' ) ;
66
7+ // See: https://github.com/nodejs/node/pull/9296
8+ const isLegacy = require ( 'compare-versions' ) ( process . version , 'v6.11.0' ) < 0 ;
9+
710// For later monkey-patching in user code
811const dnsLookup = dns . lookup ;
912
@@ -169,7 +172,7 @@ ReDNS.prototype._resolve = function _resolve(hostname, family, callback) {
169172 callback ( new Error ( 'DNS query timed out' ) ) ;
170173 } , timeout ) ;
171174
172- resolver ( hostname , options , ( err , results ) => {
175+ const onResults = ( err , results ) => {
173176 // Timed out
174177 if ( done )
175178 return ;
@@ -183,9 +186,19 @@ ReDNS.prototype._resolve = function _resolve(hostname, family, callback) {
183186 if ( typeof result === 'string' )
184187 return { address : result , ttl : Infinity , family } ;
185188
189+ // Node.js before v6.11.0 has no way to get record's TTL
190+ // fallback to `maxTTL` option
191+ if ( isLegacy )
192+ return { address : result . address , ttl : Infinity , family } ;
193+
186194 return { address : result . address , ttl : result . ttl , family } ;
187195 } ) ) ;
188- } ) ;
196+ } ;
197+
198+ if ( isLegacy )
199+ resolver ( hostname , onResults ) ;
200+ else
201+ resolver ( hostname , options , onResults ) ;
189202 } , callback ) ;
190203} ;
191204
0 commit comments