节点 js 套接字挂断和 ECONNRESET 错误 - http 从服务器获取请求下载文件

问题描述

我想从 Azure 存储中使用 nodeJS 将图像从 URL 下载到服务器,但遇到错误。 当我获取最小记录 300 到 500 时,该功能工作正常。 每当我调用 node.js 服务器获取大量记录的所有数据时,我都会收到此错误。 这是我的职能。 如何处理 ETIMEDOUT 错误?

  return new Promise((ok,notOk) => {
        try {
            const file = fs.createWriteStream(saveWhere);
            const sendReq = request.get(url);
            sendReq.on('response',(response) => {
                if (response.statusCode !== 200) {
                    console.log('error downloading file',url,'not valid response code');
                    ok();
                }
                sendReq.pipe(file);
            });
            file.on('finish',() => file.close(ok));

            sendReq.on('error',(err) => {
                console.log('error downloading file +++ 1',err);
                // fs.unlink(saveWhere);
                fs.unlink(saveWhere,function (err) {
                    if (err) {
                        console.log(" ======= unlink cb==",err)
                    }
                })
                return notOk(err);
            });
       
        
        } catch (e) {
            console.log("this is error +++ ",e);
            return not();
        }
    });

错误

Error: read ETIMEDOUT
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -110,code: 'ETIMEDOUT',syscall: 'read'
}
 
error downloading file +++ 1 Error: getaddrinfo EAI_AGAIN soneparseaapacidprodstg.blob.core.windows.net
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26) {
  errno: -3001,code: 'EAI_AGAIN',syscall: 'getaddrinfo',hostname: 'soneparseaapacidprodstg.blob.core.windows.net'
}

error downloading file +++ 1 Error: read ETIMEDOUT
    at TLSWrap.onStreamRead (internal/stream_base_commons.js:209:20) {
  errno: -110,syscall: 'read'
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)