姜同学
姜同学
  • 发布:2023-08-03 16:43
  • 更新:2023-08-07 15:10
  • 阅读:332

【报Bug】https://api-inner.next.bspapp.com/server 504

分类:uniCloud

产品分类: uniCloud/App

示例代码:

console.log('发送消息:'+id);
this.db=uniCloud.databaseForJQL({ // 获取JQL database引用,此处需要传入云对象的clientInfo
clientInfo: this.getClientInfo()
})
// this.time= uniCloud.importObject('timer')
//------------------
let dbok=true;
let dlist=[];
let num = 0;
while(dbok){
let res = await this.db.collection('uni-id-users').where(targettimes=='${id}'&&wx_openid!=null).field('wx_openid,yes').skip(100*num).limit(100).get()
res=res.data
console.log(res.length);
// console.log(res);
dlist = dlist.concat(res)
num++;
if(res.length<100){
dbok=false
}
}
res=dlist
console.log(res.length);
//---------------------
let num1 = 0;

    try{  
        let token = await tools.gettoken()  
        for(let i in res){  
            if(res[i].wx_openid!=null){  
                num1++;  
                console.log(res[i].wx_openid['h5']);  
                await tools.sendmsg(res[i].wx_openid['h5'],'[愉快]暂停一下,来记六时书吧~\nV 美德\n+ 做的好事(要为自己高兴哦[庆祝])\n- 不好的事(只记录,不评判,用四力量)\n= 即将要做的事',token)  
            }  

        }  
        console.log(num1);  
    } catch(e){  
        console.log(e);  
    }  

    return 'ok';  

tools.js
/**

  • 发客公众号消息
    */
    async sendmsg(openid, con, token) {
    try {
    await setTimeout(()=>{},100)
    let content = con
    let res = await uniCloud.httpclient.request(
    'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + token, {
    contentType: 'json',
    dataType: "json",
    timeout:600000,
    method: "POST",
    data: {
    "touser": openid,
    "msgtype": "text",
    "text": {
    "content": content
    }
    }
    })
    return res;
    } catch (e) {
    //TODO handle the exception
    console.log('发送消息报错');
    console.log(e);
    }

    },

操作步骤:

我得代码逻辑是查询数据库中的用户openid然后获取公众号token通过公众号给他们循环每个人发消息
有时候就能成功大部分都报错,504或者time超时10000毫秒,大概有几百条用户数据

预期结果:

正常请求成功进行推送

实际结果:

报错504或者time超时10000毫秒

bug描述:

我得代码逻辑是查询数据库中的用户openid然后获取公众号token通过公众号给他们循环每个人发消息
有时候就能成功大部分都报错,504或者time超时10000毫秒
报错内容


[timer/timer1691049603993-d98ebb2c-fcc3-4230-aaec-51a51738cd47/59930ms/ERROR] (node:4) UnhandledPromiseRejectionWarning: Error: Unexpected token < in JSON at position 0 (data json format: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"), POST https://api.next.bspapp.com/server 504 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 1)  
headers: {"date":"Thu, 03 Aug 2023 08:01:04 GMT","content-type":"text/html","content-length":"176","connection":"keep-alive","set-cookie":["acw_tc=2760820416910496041818894e2bbbc8eac6a7a71e5c8f060a9dbcddf82af9;path=/;HttpOnly;Max-Age=1800"],"via":"HTTP/1.1 SLB.20"}  
    at e.$scope.function.invoke.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:95698)  
    at <anonymous>  
    at process._tickCallback (internal/process/next_tick.js:189:7)  
[timer/timer1691049603993-d98ebb2c-fcc3-4230-aaec-51a51738cd47/59930ms/ERROR] (node:4) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)  
[timer/timer1691049603993-d98ebb2c-fcc3-4230-aaec-51a51738cd47/59930ms/ERROR] (node:4) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.  
[timer/timer1691049603993-d98ebb2c-fcc3-4230-aaec-51a51738cd47/60073ms/ERROR] Unexpected token < in JSON at position 0 (data json format: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"), POST https://api-inner.next.bspapp.com/server 504 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 1)  
headers: {"date":"Thu, 03 Aug 2023 08:01:04 GMT","content-type":"text/html","content-length":"176","connection":"keep-alive","via":"HTTP/1.1 SLB.216"}  
Error: Unexpected token < in JSON at position 0 (data json format: "<html>\r\n<head><title>504 Gateway Time-out</title></head>\r\n<body bgcolor=\"white\">\r\n<center><h1>504 Gateway Time-out</h1></center>\r\n<hr><center>nginx</center>\r\n</body>\r\n</html>\r\n"), POST https://api-inner.next.bspapp.com/server 504 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 1)  
headers: {"date":"Thu, 03 Aug 2023 08:01:04 GMT","content-type":"text/html","content-length":"176","connection":"keep-alive","via":"HTTP/1.1 SLB.216"}  
    at e.$scope.function.invoke.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:95698)  
    at <anonymous>  
    at process._tickCallback (internal/process/next_tick.js:189:7)  
请求响应状态: fail  

我得代码

2023-08-03 16:43 负责人:无 分享
已邀请:
姜同学

姜同学 (作者) - demo

没人看下吗,都耽误正常运营了

DCloud_uniCloud_WYQ

DCloud_uniCloud_WYQ

现在还有这个报错吗?阿里那边排查到是你这个云函数的某个实例出现了问题,现在已经自动恢复了。阿里下次发版会修正这个问题

  • 姜同学 (作者)

    有的还是报错,Response timeout for 300000ms, POST https://api-inner.next.bspapp.com/server -1 还是超时

    2023-08-08 20:29

  • 姜同学 (作者)

    回复 8***@qq.com: 应该是设置的600000ms一半时间就超时了

    2023-08-08 20:34

  • 姜同学 (作者)

    [timer/ac1cc3061691503100965170205/375750ms/ERROR] (node:4) UnhandledPromiseRejectionWarning: Error: Response timeout for 300000ms, POST https://api-inner.next.bspapp.com/server -1 (connected: true, keepalive socket: false, socketHandledRequests: 1, socketHandledResponses: 0)

    headers: {}

    at e.$scope.function.invoke.then.catch.e (/tmp/function/@dcloudio/serverless/lib/aliyun/uni-cloud.js:1:95698)

    at <anonymous>

    2023-08-08 22:09

  • DCloud_uniCloud_WYQ

    回复 8***@qq.com: 你被调用的云函数是干什么的?一定会运行超过30秒吗?

    2023-08-09 11:00

  • 姜同学 (作者)

    回复 DCloud_uniCloud_WYQ: 对的是批量发送公众号客服消息,有1000多条

    2023-08-10 19:40

  • 姜同学 (作者)

    回复 8***@qq.com: 总会超时,引入云函本身,想分批发送。也会报错 https://api.next.bspapp.com/server 504或者-1报错

    2023-08-10 19:42

  • DCloud_uniCloud_WYQ

    回复 8***@qq.com: 引入云函本身,想分批发送。也会报错 https://api.next.bspapp.com/server 504或者-1报错 这个能私聊发我一下服务空间id、云函数名、requestId和日志内容吗

    2023-08-11 11:17

  • 姜同学 (作者)

    回复 DCloud_uniCloud_WYQ: 你好发过去了,辛苦了

    2023-08-11 20:22

要回复问题请先登录注册