7***@qq.com
7***@qq.com
  • 发布:2022-11-26 14:28
  • 更新:2023-08-30 18:31
  • 阅读:334

【报Bug】云函数本地运行正常,上传部署后报错

分类:uniCloud

产品分类: uniCloud/App

操作步骤:

上传部署后执行

uniCloud.callFunction({  
                name: 'addNewsHeNan',  
                complete(res) {  
                    console.log('结果', res)  
                }  
            })

预期结果:

得到正确的第三方返回的数据

实际结果:
 Error: [addNewsHeNan]: ENOTFOUND:getaddrinfo ENOTFOUND v.api.aa1.cn v.api.aa1.cn:443, GET https:/xxx  -1 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":1,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"xxxx:443:::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)  
headers: {}

bug描述:

'use strict';  
exports.main = async (event, context) => {  
    //event为客户端上传的参数  
    console.log('event : ', event);  
    const dbJQL = uniCloud.databaseForJQL({   
        event,  
        context   
    });  
    const page = event.page ||  0  
    const url = "https://xxxxx";  
    const detail_url = 'https://xxxxxxx'  
    const res = await uniCloud.httpclient.request(url, {  
        method: 'GET',  
        data: {},  
        contentType: 'json', // 指定以application/json发送data内的数据  
        dataType: 'json' // 指定返回值为json格式,自动进行parse  
     });  
     let listNes = [];  
     let requests = [];  
     let lastResult  = [];  
     if(res.status == 200) {  
         if(res.data.code == 1) {  
            const tempList = res.data.data;  
            console.log('tempList', tempList)  
            for(let i=0;i<tempList.length;i++) {  
                const item = tempList[i];  
                const result = await dbJQL.collection("xxx")get();  
                if(!result.data) {  
                    requests.push({data: item});  
                };  
            };  
         };  
     };  
       let promiseRequest = []  
       for(let i=0;i<requests.length; i++) {  
            const item = requests[i].data;  
            const p =  new Promise((resolve, reject) => {  
                resolve(i);  
           })  
           promiseRequest.push({item, p})  
       }  

        for(let i=0;i<promiseRequest.length;i++) {  
            const promisea = promiseRequest[i]  
            const r = await promisea.p  
            const item = await promisea.item  
            await new Promise((resolve,reject) => {  
                    setTimeout(() => {  
                        uniCloud.httpclient.request(detail_url, {  
                            method: 'GET',  
                            data: {},  
                            contentType: 'json', // 指定以application/json发送data内的数据  
                            dataType: 'json' // 指定返回值为json格式,自动进行parse  
                         }).then(result => {  
                            if(result.result.data.code == 1) {  
                                const detail =  result.result.data.data;  
                                const create_date = new Date(item.ptime).getTime();  
                                console.log("create_date", create_date)  
                                listNes.push({id:item.docid, create_date})  
                                dbJQL.collection("xxx").add({  
                                    "docid": item.docid  
                                });  
                                resolve()  

                            }   
                         })         
                    }, 5*1000)  
            })  

        }  
        console.log('执行完毕')  
        return {res:listNes, msg: '执行完毕'}  
};  

代码如上,做了延时请求第三方API的处理,本地调试是正常的,但是部署之后报错:

 Error: [addNewsHeNan]: ENOTFOUND:getaddrinfo ENOTFOUND v.api.aa1.cn v.api.aa1.cn:443, GET https:/xxx  -1 (connected: false, keepalive socket: false, agent status: {"createSocketCount":1,"createSocketErrorCount":0,"closeSocketCount":0,"errorSocketCount":1,"timeoutSocketCount":0,"requestCount":0,"freeSockets":{},"sockets":{"xxxx:443:::::::::":1},"requests":{}}, socketHandledRequests: 1, socketHandledResponses: 0)  
headers: {}

xxxx代表请求域名

这个问题困扰两天了,希望能得到官方解答!!!!

2022-11-26 14:28 负责人:无 分享
已邀请:
7***@qq.com

7***@qq.com (作者)

在我编写云函数代码时,无意间引入了一个 inport resolve form 'dns';
后来看到后就删掉了,但是不确定是否因为引入这个之后所导致的,
报错信息里有这样一段 GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:67:26)
如果是这个原因,该怎么解决呢?

DCloud_uniCloud_CRL

DCloud_uniCloud_CRL

域名解析了吗?

wenxr

wenxr

解决了吗?我也遇到了同样的问题

要回复问题请先登录注册