I have some timeout problems when calling the HTTP [S] endpoint multiple times from node.js inside Azure application service.
Here is my code to demonstrate the problem.
const fetch = require('node-fetch');
const https = require("https");
const agent = new https.Agent();
function doWork() {
const works = [];
for (let i = 0; i < 50; i++) {
const wk = fetch('https://www.microsoft.com/robots.txt', { agent })
.then(res => res.text())
.then(body => console.log("OK", i))
.catch((err) => console.log("ERROR", i, err));
works.push(wk);
}
return Promise.all(works);
}
doWork()
.catch((err) => {
console.log(err);
});
When I run this application 3 or 4 times in the service of the standard mid-sized application (I launch it using Kudu, but I find this error in the standard web application). I get the following error for each request:
{ FetchError: request to https://www.microsoft.com/robots.txt failed, reason: connect ETIMEDOUT 23.206.106.109:443
at ClientRequest.<anonymous> (D:\home\site\test\test-forge-calls\node_modules\node-fetch\lib\index.js:1393:11)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:310:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at emitErrorNT (net.js:1276:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
message: 'request to https://www.microsoft.com/robots.txt failed, reason: connect ETIMEDOUT 23.206.106.109:443',
type: 'system',
errno: 'ETIMEDOUT',
code: 'ETIMEDOUT' }
After a few minutes (5/6) without executing the requests, the above code works again.
node-fetch (https://www.npmjs.com/package/node-fetch) request (https://www.npmjs.com/package/request). .
, agent , ( ).
Microsoft Best Practices node.js keep alive agent :
var keepaliveAgent = new Agent({
maxSockets: 40,
maxFreeSockets: 10,
timeout: 60000,
keepAliveTimeout: 300000
});
:
const agent = new https.Agent({ maxSockets: 100 });
, .
? node.js? agent maxSockets Azure?
UPDATE:
, node index 3 4 , , node, , . TIME_WAIT?