wechaty / puppet-supports

Wechaty Puppet Services (WPS)
https://wechaty.js.org/docs/puppet-services/
Apache License 2.0
33 stars 4 forks source link

[FEAT]WorkPro: chatbot stops receiving messages after 3 to 4 days and encounters a log error #579

Open junmo1215 opened 2 weeks ago

junmo1215 commented 2 weeks ago

Describe the bug

I implemented my chatbot using Wechaty (WorkPro). Initially, when I start my service, it can send and receive messages normally. However, after 3 to 4 days, it stops receiving messages. Checking the logs reveals the following error, and no further logs are printed afterward.

17:14:33 VERB PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT(1), payload(len:28)})
17:14:48 VERB PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT(1), payload(len:28)})
17:15:03 VERB PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT(1), payload(len:28)})
17:15:18 VERB PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT(1), payload(len:28)})
17:15:33 VERB PuppetService onGrpcStreamEvent({type:EVENT_TYPE_HEARTBEAT(1), payload(len:28)})
17:15:35 ERR Config ###########################
17:15:35 ERR Config Wechaty uncaughtException: Error: 1 CANCELLED: Call cancelled
    at callErrorFromStatus (/app/wechaty/node_modules/@grpc/grpc-js/src/call.ts:82:17)
    at Object.onReceiveStatus (/app/wechaty/node_modules/@grpc/grpc-js/src/client.ts:611:51)
    at Object.onReceiveStatus (/app/wechaty/node_modules/@grpc/grpc-js/src/client-interceptors.ts:419:48)
    at /app/wechaty/node_modules/@grpc/grpc-js/src/resolving-call.ts:132:24
    at processTicksAndRejections (node:internal/process/task_queues:77:11)
for call at
    at ServiceClientImpl.makeServerStreamRequest (/app/wechaty/node_modules/@grpc/grpc-js/src/client.ts:594:42)
    at ServiceClientImpl.event (/app/wechaty/node_modules/@grpc/grpc-js/src/make-client.ts:189:15)
    at GrpcManager.startStream (/app/wechaty/node_modules/wechaty-puppet-service/src/client/grpc-manager.ts:298:37)
    at GrpcManager.start (/app/wechaty/node_modules/wechaty-puppet-service/src/client/grpc-manager.ts:160:16)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PuppetService.onStart (/app/wechaty/node_modules/wechaty-puppet-service/src/client/puppet-service.ts:173:5)
    at async PuppetService.start (/app/wechaty/node_modules/state-switch/src/service-ctl/service-ctl.ts:89:9)
    at async PuppetService.start (/app/wechaty/node_modules/wechaty-puppet/src/mixins/service-mixin.ts:34:7)
    at async PuppetService.start (/app/wechaty/node_modules/wechaty-puppet/src/mixins/ready-mixin.ts:24:7)
    at async WechatyImpl.start (/app/wechaty/node_modules/wechaty/src/wechaty-mixins/puppet-mixin.ts:83:11) uncaughtException
17:15:35 ERR Config ###########################
17:15:35 VERB PuppetService bridgeGrpcEventStream() eventStream.on(end)
17:15:36 WARN ResolverWechaty updateResolution() address not found target wechaty://token-service-discovery-test.juzibot.com/puppet_workpro_{my token}: token does not exist
17:16:33 WARN PuppetWatchdogAgent start() reset() reason: {"data":"regular heartbeat","timeoutMilliseconds":60000}
17:16:33 ERR Config ###########################
17:16:33 ERR Config Wechaty uncaughtException: Error: WatchdogAgent reset: lastFood: "{"data":"regular heartbeat","timeoutMilliseconds":60000}"
    at Watchdog.reset (/app/wechaty/node_modules/wechaty-puppet/src/agents/watchdog-agent.ts:65:33)
    at Watchdog.emit (node:events:519:28)
    at Watchdog.emit (node:domain:488:12)
    at Timeout._onTimeout (/app/wechaty/node_modules/watchdog/src/watchdog.ts:115:12)
    at listOnTimeout (node:internal/timers:573:17)
    at processTimers (node:internal/timers:514:7) uncaughtException
17:16:33 ERR Config ###########################

Info

To Reproduce

Steps to reproduce the behavior: Start my app with the fellowing code and wait:

const wechaty_bot = WechatyBuilder.build({
  name: 'xxx'
})

wechaty_bot.on('scan',    onScan)
wechaty_bot.on('login',   onLogin)
wechaty_bot.on('logout',  onLogout)
wechaty_bot.on('message', onMessage)

CmdHelper.set_bot(wechaty_bot);

wechaty_bot.start()
  .then(() => {
    log.info('StarterBot', 'Starter Bot Started.')
  })
  .catch(e => log.error('StarterBot', 'Failed to start the bot:', e))

Additional context

hcfw007 commented 5 hours ago

这说明你本地与远程服务器连接断了。请监听 error 事件并编码重连。