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

Calling log-update breaks SIGINT signal handlers #17

Closed
laurynaslubys opened this issue Apr 17, 2017 · 2 comments
Closed

Calling log-update breaks SIGINT signal handlers #17

laurynaslubys opened this issue Apr 17, 2017 · 2 comments

Comments

@laurynaslubys
Copy link
Contributor

It seems that using this library breaks the expected behaviour of SIGINT listeners. If logUpdate is used before registering a SIGINT listener, the listener is not called at all and the process exits immediately, if logUpdate is first called after registering a listener, the listener is called, but the process still exits. If logUpdate is not called, the code below doesn't exit of first SIGINT, but does so on the second one (which is the expected behaviour)

const logUpdate = require('log-update')

//logUpdate('This makes my SIGINT listener not called at all, and the process immediately exits')

process.stdin.on('data', () => {
	// just so we don't exit
})

let count = 0
process.on('SIGINT', () => {
	if (count >= 1) {
		process.exit(0)
	}
	console.log('press CTRL+C again to exit')
	count ++ 
})

//logUpdate('this makes my SIGINT listener be called, but the process still exits')

Uncommenting only the first usage yields

~/IdeaProjects/temp$ node index.js
This makes my SIGINT handler not called at all, and the process immediately exits
^C~/IdeaProjects/temp$

Uncommenting only the second usage yields

~/IdeaProjects/temp$ node index.js
this makes my SIGINT handler be called, but the process still exits
^Cpress CTRL+C again to exit
~/IdeaProjects/temp$

Uncommenting both yields

~/IdeaProjects/temp$ node index.js
^Cpress CTRL+C again to exit
^C~/IdeaProjects/temp$

Tested on node v6.10.1 and v7.7.4, macOS 10.12.3 (16D32)

@laurynaslubys laurynaslubys changed the title Calling log-update break SIGINT signal handlers Calling log-update breaks SIGINT signal handlers Apr 17, 2017
@laurynaslubys
Copy link
Contributor Author

Any ETA on when this will be released?

okonet pushed a commit to okonet/listr-update-renderer that referenced this issue Sep 13, 2018
This version should fix issues related to processing of SIGINT signal. See sindresorhus/log-update#17. Related to SamVerschueren/listr#85
@ivan-kleshnin
Copy link

For some reason logUpdate blocks SIGINT if at least one timer (setInterval / setTimeout) is running:

import logUpdate from "log-update"

logUpdate("test")
setInterval(() => console.log(new Date()), 1000)
// Try to Ctrl-C...

A workaround is to manually clear an interval.

process.on("SIGINT", () => {
  clearInterval(interval)
  logUpdate.done()  
})

Still I'm curios why it happens... if someone knows – please share 🙏

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

2 participants