Azure 函数应用程序 ETIMEDOUT 错误有时有效但其他无效

Azure function app ETIMEDOUT error works sometimes but not others

我有以下代码:

var request = require('request');
var rp = require('request-promise');
module.exports = async function(context, req) {
    var arr = [[url1],[url2]]
    for (i = 0; i < arr.length; i++) {
        func(context, arr[i]);
    }
}
function func(context, urls) {
    const promises = urls.map(item => {
        return rp({
            uri: item,
            simple: false,
            resolveWithFullResponse: true
        }).then(response => {
            if (response.statusCode == 403) {

                var msg = "hello";
                return msg;
            } else {
                return null;
            }
        });
    });

    return Promise.all(promises).then(data => {
        // remove null results from array
        return data.filter(item => item !== null);
    });
}

而且我不断收到此错误。有时有效,有时无效。我该如何解决这个问题,为什么有时有效有时无效。

Result: Failure
Exception: RequestError: Error: connect ETIMEDOUT 

我需要包含 pool 选项吗?或者也许 timeout?错误似乎是由于 arr.

的大小造成的

这是网络级别的问题,很可能与您的代理配置有关。当使用没有有效证书的 https(端口 443)向服务器请求时,您也可能会收到此错误。因此,使用以下配置可以解决您的问题。

return rp({
       uri: item,
       simple: false,
       resolveWithFullResponse: true,
       proxy: 'http://<your.proxy.info>:8080',
       strictSSL :false
})

更新:

没有代理,没有流,只有一个请求启动多个异步请求,设置这个选项:

agent: false, pool: {maxSockets: 8}