Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions clients/javascript/lib/baseClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,26 +400,40 @@ export const createAxiosInstanceBackend = async (
typeof module !== 'undefined' &&
module.exports
) {
// This is a dynamic import to avoid loading this module in the browser
const CacheableLookupLib = await import('cacheable-lookup')

// Create a cacheable lookup instance
// Goal is to make DNS lookup fully async + avoid hitting the limit of 4 UV threads
// See https://marmelab.com/blog/2025/07/28/dns-in-nodejs.html (for example) on the subject
const cacheableLookup = new CacheableLookupLib.default()

if (args.baseUrl.startsWith('https')) {
// This is a dynamic import to avoid loading the https module in the browser
const https = await import('node:https')
// Default values are what we evaluated to be good for our load
config.httpsAgent = new https.Agent({
const httpsAgent = new https.Agent({
keepAlive: true,
maxSockets: args.keepAlive.maxSockets ?? 75,
maxFreeSockets: args.keepAlive.maxFreeSockets ?? 10,
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
})

cacheableLookup.install(httpsAgent)
config.httpsAgent = httpsAgent
} else {
// This is a dynamic import to avoid loading the http module in the browser
const http = await import('node:http')
// Default values are what we evaluated to be good for our load
config.httpAgent = new http.Agent({
const httpAgent = new http.Agent({
keepAlive: true,
maxSockets: args.keepAlive.maxSockets ?? 75,
maxFreeSockets: args.keepAlive.maxFreeSockets ?? 10,
keepAliveMsecs: args.keepAlive.keepAliveMsecs ?? 60000,
})

cacheableLookup.install(httpAgent)
config.httpAgent = httpAgent
}
}

Expand Down
1 change: 1 addition & 0 deletions clients/javascript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"dependencies": {
"axios": "1.12.2",
"axios-retry": "4.5.0",
"cacheable-lookup": "^7.0.0",
"dayjs": "1.11.18"
},
"devDependencies": {
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.