Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using hot-import cannot quit wechaty when quit the code #978

Closed
lijiarui opened this issue Nov 20, 2017 · 9 comments
Closed

Using hot-import cannot quit wechaty when quit the code #978

lijiarui opened this issue Nov 20, 2017 · 9 comments

Comments

@lijiarui
Copy link
Member

lijiarui commented Nov 20, 2017

When I Using hot-import of wechaty, when I quit the code, but it seems wechaty still work background, log as follows.

➜  ticket-bot git:(master) ✗ 16:34:41 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
16:34:51 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
(node:7403) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 watchdog listeners added. Use emitter.setMaxListeners() to increase limit
16:35:14 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000

➜  ticket-bot git:(master) ✗
➜  ticket-bot git:(master) ✗ 16:36:42 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
(node:7544) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 scan listeners added. Use emitter.setMaxListeners() to increase limit
(node:7544) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 login listeners added. Use emitter.setMaxListeners() to increase limit
(node:7544) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 logout listeners added. Use emitter.setMaxListeners() to increase limit
16:36:52 WARN PuppetWeb initWatchdogForPuppet() dog.on(reset) last food:inited, timeout:120000
(node:7544) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 heartbeat listeners added. Use emitter.setMaxListeners() to increase limit
@lijiarui
Copy link
Member Author

should add bot.stop() when exit the process.

const finis = require('finis')
finis(async (code, signal) => {
  const exitMsg = `Wechaty exit ${code} because of ${signal} `
  await bot.stop()
  console.log(exitMsg)
  bot.say(exitMsg)
})

@lijiarui lijiarui mentioned this issue Nov 20, 2017
@lijiarui
Copy link
Member Author

lijiarui commented Nov 20, 2017

It seems it is not wechaty cannot quit, but some monitor thing doesn't quit.
When I quit the program, then change the file, I will get the following log

10:37:46 INFO Bot DingDong! 我上线啦,你可以来和我订机票啦!
10:37:46 INFO Wechaty announce(DingDong! 我上线啦,你可以来和我订机票啦!)
10:37:46 VERB Wechaty announce() got 0 rooms
10:37:46 VERB Wechaty announce() to self because no room found



^C
lijiarui:~/workspace (master) $ 10:38:01 WARN PuppetWebBridge quit() page.close() exception: Error: Protocol error (Target.closeTarget): Target closed.
Wechaty exit 130 because of SIGINT 
(node:36952) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: no puppet

lijiarui:~/workspace (master) $ 10:38:41 ERR HotImport importFile(/home/ubuntu/workspace/src/listeners/message.ts) rejected: TSError: ⨯ Unable to compile TypeScript
src/listeners/message.ts (8,12): Cannot find name 'BOTBUILDERAPPID'. (2304)
src/listeners/message.ts (9,18): Cannot find name 'BOTBUILDERPSW'. (2304)
src/listeners/message.ts (12,7): 'MsBot' is declared but its value is never read. (6133)
src/listeners/message.ts (12,51): Block-scoped variable 'startBot' used before its declaration. (2448)
src/listeners/message.ts (12,51): Variable 'startBot' is used before being assigned. (2454)
10:38:41 ERR HotImport refreshImport(/home/ubuntu/workspace/src/listeners/message.ts) exception: TSError: ⨯ Unable to compile TypeScript
src/listeners/message.ts (8,12): Cannot find name 'BOTBUILDERAPPID'. (2304)
src/listeners/message.ts (9,18): Cannot find name 'BOTBUILDERPSW'. (2304)
src/listeners/message.ts (12,7): 'MsBot' is declared but its value is never read. (6133)
src/listeners/message.ts (12,51): Block-scoped variable 'startBot' used before its declaration. (2448)
src/listeners/message.ts (12,51): Variable 'startBot' is used before being assigned. (2454)
10:38:41 ERR HotImport refreshImport(/home/ubuntu/workspace/src/listeners/message.ts) keep using the latest usable version
10:38:41 ERR HotImport importFile(/home/ubuntu/workspace/src/listeners/message.ts) rejected: TSError: ⨯ Unable to compile TypeScript
src/listeners/message.ts (8,12): Cannot find name 'BOTBUILDERAPPID'. (2304)

Then, I found node still running on the background

lijiarui:~/workspace (master) $ ps -A
    PID TTY          TIME CMD
      1 ?        00:00:01 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
  36045 ?        00:00:00 dropbear
  36046 ?        00:00:01 vfs-worker {"pi
  36493 pts/0    00:00:00 tmux
  36952 pts/1    00:00:04 node
  37062 pts/1    00:00:00 ps

code as follows:

import { Wechaty, Room } from 'wechaty'
import { log, TICKETBOT_SECRET } from './config'
export const bot = Wechaty.instance()
const finis = require('finis')

bot
.on('scan',     './listeners/scan')
.on('logout',   './listeners/logout')
.on('error',    './listeners/error')
.on('login',    './listeners/login')
.on('message',  './listeners/message')
.start()
.catch(async function(e) {
  log.error('Bot', 'init() fail: %s', e)
  await bot.stop()
  process.exit(-1)
})

finis(async (code, signal) => {
  const exitMsg = `Wechaty exit ${code} because of ${signal} `
  await bot.stop()
  console.log(exitMsg)
})

@lijiarui
Copy link
Member Author

lijiarui commented Nov 20, 2017

I found the solution! should add process.exit(-1) at finis, as follows

finis(async (code, signal) => {
  const exitMsg = `Wechaty exit ${code} because of ${signal} `
  await bot.stop()
  console.log(exitMsg)
  process.exit(-1)
})

Actually, I think it should be done by wechaty itself instead by user, because wechaty is a 'platform' solution.

@huan
Copy link
Member

huan commented Nov 20, 2017

Your solution looks like a dirty fix.

What if you remove all the finis part of the code?

@lijiarui
Copy link
Member Author

lijiarui commented Nov 20, 2017

If I remove all finis part, when I quit the code, node and chrom also work background, as the following shows

https://login.weixin.qq.com/qrcode/4Y04lLO_YQ==
14:22:39 INFO Listeners/Scan https://login.weixin.qq.com/qrcode/4Y04lLO_YQ==
[0]
^C
lijiarui:~/workspace (master) $ ps -A
    PID TTY          TIME CMD
      1 ?        00:00:01 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
  37393 pts/1    00:00:00 node
  37403 pts/1    00:00:44 node
  37647 pts/3    00:00:00 bash
  37648 pts/3    00:00:00 bash
  40297 ?        00:00:00 dropbear
  40298 ?        00:00:01 vfs-worker {"pi
  40465 pts/0    00:00:00 tmux
  40467 pts/2    00:00:00 tmux
  41227 pts/3    00:00:06 node
  41300 ?        00:00:02 chrome
  41305 ?        00:00:00 chrome
  41326 ?        00:00:00 chrome
  41333 ?        00:00:10 chrome
  41374 pts/3    00:00:00 ps

code as follows

import { Wechaty, Room } from 'wechaty'
export const bot = Wechaty.instance()

bot
.on('scan',     './listeners/scan')
.on('logout',   './listeners/logout')
.on('error',    './listeners/error')
.on('login',    './listeners/login')
.on('message',  './listeners/message')
.start()
.catch(async function(e) {
  log.error('Bot', 'init() fail: %s', e)
  await bot.stop()
  process.exit(-1)
})

@lijiarui
Copy link
Member Author

@zixia
Run the repo example can reproduce this.
run ts-node example/roger-bot.ts (roger-bot)

@huan
Copy link
Member

huan commented Nov 26, 2017

I do not think this issue relates to hot-import.

@lijiarui
Copy link
Member Author

Due to a typescript bug

@suntong
Copy link
Contributor

suntong commented Feb 26, 2018

@lijiarui (and maybe @zixia as well), when closing the issue, please use e.g., 'close #978' in the git comment so that the fix can be linked back to the issue, and vice versa, people can use the issue to find the fix.

thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants