Wechaty: How to avoid the memory leak

Created on 22 Nov 2017  路  7Comments  路  Source: wechaty/wechaty

When I running wechaty for a while using npm package and hot-import module, I got the following logs

07:58:29 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:00:32 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:02:34 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:04:36 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:06:39 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:08:42 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:10:44 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
08:12:47 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
(node:59547) Warning: Possible EventEmitter memory leak detected. 11 scan listeners added. Use emitter.setMaxListeners() to increase limit
(node:59547) Warning: Possible EventEmitter memory leak detected. 11 login listeners added. Use emitter.setMaxListeners() to increase limit
(node:59547) Warning: Possible EventEmitter memory leak detected. 11 logout listeners added. Use emitter.setMaxListeners() to increase limit
(node:59547) Warning: Possible EventEmitter memory leak detected. 11 heartbeat listeners added. Use emitter.setMaxListeners() to increase limit
08:14:49 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
(node:59547) Warning: Possible EventEmitter memory leak detected. 11 watchdog listeners added. Use emitter.setMaxListeners() to increase limit

How can I avoid this memory leak?

When I kill the process, I also can see a lot of chrome work background

lijiarui:~/workspace (master) $ ps -A
    PID TTY          TIME CMD
      1 ?        00:00:07 tini
      7 ?        00:00:00 micro-inetd
  34436 ?        00:00:00 tmux
  34437 pts/1    00:00:00 bash
  34438 pts/1    00:00:00 bash
  59079 ?        00:00:32 chrome
  59081 ?        00:00:00 chrome
  59102 ?        00:00:06 chrome
  59110 ?        00:01:13 chrome
  59220 ?        00:00:35 chrome
  59222 ?        00:00:00 chrome
  59243 ?        00:00:05 chrome
  59250 ?        00:01:18 chrome
  59468 ?        00:00:14 chrome
  59470 ?        00:00:00 chrome
  59491 ?        00:00:01 chrome
  59498 ?        00:01:04 chrome
  60100 ?        00:00:00 dropbear
  60101 ?        00:00:04 vfs-worker {"pi
  61144 pts/0    00:00:00 tmux
  62106 ?        00:00:00 chrome
  62108 ?        00:00:00 chrome
  62129 ?        00:00:00 chrome
  62136 ?        00:00:02 chrome
  62185 pts/1    00:00:00 ps

When I kill all relate process and restart a bot, then I found it still run a lot of chrom background

lijiarui:~/workspace (master) $ ps -A
    PID TTY          TIME CMD
      1 ?        00:00:07 tini
      7 ?        00:00:00 micro-inetd
  34436 ?        00:00:00 tmux
  34437 pts/1    00:00:00 bash
  34438 pts/1    00:00:00 bash
  60100 ?        00:00:00 dropbear
  60101 ?        00:00:04 vfs-worker {"pi
  61144 pts/0    00:00:00 tmux
  62230 pts/1    00:00:00 node
  62240 pts/1    00:00:04 node
  62250 ?        00:00:02 chrome
  62252 ?        00:00:00 chrome
  62273 ?        00:00:00 chrome
  62280 ?        00:00:06 chrome
  62326 pts/2    00:00:00 tmux
  62328 pts/3    00:00:00 bash
  62329 pts/3    00:00:00 bash
  62791 pts/3    00:00:00 ps
bug

All 7 comments

Please provide the reproduce steps.

And also instead of asking how, it's better to provide a pull request to fix it.

maybe it is related to #978 but I'm not sure... still dig in it.

Using silly log, just run the smallest wechaty getting started demo will get the following result, maybe there are too many checkScan here.

07:22:39 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:40 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:41 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:42 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:43 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:44 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:45 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:46 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:47 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:48 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:49 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:50 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:51 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:52 SILL PuppetWebEvent onDing(heartbeat@browser)
07:22:52 SILL PuppetWeb initWatchdogForPuppet() dog.on(feed, food={type=undefined, data=heartbeat@browser})
07:22:52 SILL Wechaty memoryCheck() free: 3809 MB, require: 4 MB
07:22:52 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:53 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:54 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:55 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:56 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:57 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:58 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:22:59 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:23:00 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:23:01 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)
07:23:02 SILL PuppetWebEvent onLog(checkScan() code:0 url:https://login.weixin.qq.com/qrcode/4djX8rs1VA== scanCode:0)

This is a typescript bug

There do have a memory leak. Please keep this issue open.

Should have been fixed by the related commit.

image

The error appears after starting wechaty for 5 days .

Was this page helpful?
0 / 5 - 0 ratings