@@ -77,12 +77,14 @@ let imdsTokenCache = undefined;
7777let imdsRegionCache = undefined ;
7878let imdsCredentialsCache = undefined ;
7979const dnsCache = new LRUCache ( { max : 1000 , ttl : DNS_RECORD_MAX_TTL_IN_SECONDS * 1000 } ) ;
80+ const resolverCache = new LRUCache ( { max : 100 } ) ;
8081
8182exports . clearCache = ( ) => {
8283 imdsTokenCache = undefined ;
8384 imdsRegionCache = undefined ;
8485 imdsCredentialsCache = undefined ;
8586 dnsCache . clear ( ) ;
87+ resolverCache . clear ( ) ;
8688} ;
8789
8890function parseContentRange ( contentRange ) {
@@ -100,8 +102,22 @@ function parseContentRange(contentRange) {
100102 }
101103}
102104
105+ function fetchResolver ( timeoutInMilliseconds ) {
106+ let resolver = resolverCache . get ( timeoutInMilliseconds ) ;
107+ if ( resolver !== undefined ) {
108+ return resolver ;
109+ }
110+ const resolverOptions = { tries : 1 } ;
111+ if ( timeoutInMilliseconds > 0 ) {
112+ resolverOptions . timeout = timeoutInMilliseconds ;
113+ }
114+ resolver = new Resolver ( resolverOptions ) ;
115+ resolverCache . set ( timeoutInMilliseconds , resolver ) ;
116+ return resolver ;
117+ }
118+
103119function request ( nodemodule , requestOptions , body , timeoutOptions , cb ) {
104- const resolver = new Resolver ( { timeout : timeoutOptions . resolveTimeoutInMilliseconds , tries : 1 } ) ;
120+ const resolver = fetchResolver ( timeoutOptions . resolveTimeoutInMilliseconds ) ;
105121 requestOptions . lookup = ( hostname , options , cb ) => {
106122 if ( typeof options === 'function' ) {
107123 cb = options ;
@@ -377,11 +393,11 @@ exports.imds = imds;
377393
378394const DEFAULT_IMDS_TIMEOUT_OPTIONS = {
379395 requestTimeoutInMilliseconds : 3000 ,
380- resolveTimeoutInMilliseconds : 1000 ,
381- connectionTimeoutInMilliseconds : 1000 ,
382- readTimeoutInMilliseconds : 1000 ,
383- dataTimeoutInMilliseconds : 1000 ,
384- writeTimeoutInMilliseconds : 1000
396+ resolveTimeoutInMilliseconds : 0 ,
397+ connectionTimeoutInMilliseconds : 3000 ,
398+ readTimeoutInMilliseconds : 0 ,
399+ dataTimeoutInMilliseconds : 0 ,
400+ writeTimeoutInMilliseconds : 0
385401} ;
386402
387403function refreshAwsRegion ( ) {
0 commit comments