wechaty / wechaty-puppet-padplus

DEPRECATED: One puppet based on iPad protocal for Wechaty
https://wechaty.js.org/docs/puppet-services/
315 stars 65 forks source link

Run into GrpcGateway's "can not find callback by traceId" error on an Aliyun production server #267

Open archywillhe opened 4 years ago

archywillhe commented 4 years ago

Important:Please file the issue follow the template, or we won't help you to solve the problem.

0. Report Issue Guide

  1. Please run the following command and check whether the problem has been fixed:

    rm -rf package-lock.json
    rm -rf node_modules
    npm install
  2. Please search in FAQ List first, and make sure your problem has not been solved before.

  3. Please search in the issue first, and make sure your problem had not been reported before

1. Versions

2. Describe the bug

After deploying new code to the production server, and restarting pm2, and waiting for WeChaty to finish initialisation i.e. after onLogin is called, I send a message to the chatbot and expect the chatbot to send me back 7~10 messages.

Instead I will often get 4~6 messages.

What happens is that at one point, the chatbot sends a message and throws the following error and the script stops running.

Error: can not find callback by traceId : 8e86faec-0794-400e-a8df-xxxxxxx
at GrpcGateway.<anonymous> (/home/git/live/archybot/node_modules/wechaty-puppet-padplus/src/server-manager/grpc-gateway.ts:488:19)
at Generator.next (<anonymous>)
at fulfilled (/home/git/live/archybot/node_modules/wechaty-puppet-padplus/dist/src/server-manager/grpc-gateway.js:5:58)

3. To Reproduce

Not always reproduciable. Happens sometimes after restarting the server. The problem often disappears after the first encountering and the chatbot will behave normally.

I have the following function to perform a sequential execution of promises.

const sequenctial = async (tasks:any, transformation:(a:any)=>any, sideEffect:(a:any)=>void):Promise<any[]> => {
  const results : any[] = [];

  for (const task of tasks) {
    const result = await transformation(task);
    await sideEffect(result)
    results.push(result);
  }

  return results;
};

and it is used like this:

            const newArray = await sequenctial(array,transformation,async (a)=>{
              await msg.say(
               a.word+" "+a.pinyin+"\n"+
               (a.meaning || "unknown")
              )
            })

Most time everything works well. Only encounter the error sometimes.

4. Expected behavior

Most of the time the script runs properly i.e. the chatbot will send me back 7~10 messages instead of running into the error halfway.

5. Actual behavior

Sometimes the script stops halfway and throws the error. And I don't receive the remaining messages. This has only happened on my production server hosted on Aliyun.

6. Full Output Logs

Hasn't been able to reproduce after turnning on WECHATY_LOG=silly.

Will update the issue again when the error is encountered.

7. Additional context

The Aliyun production server is hosted in Hangzhou.

[bug]