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

signal handling: Not working and triggering 100% cpu when no timers are active #11

Open
awelzel opened this issue Apr 10, 2022 · 2 comments

Comments

@awelzel
Copy link
Collaborator

awelzel commented Apr 10, 2022

Running zeek with the following script and sending SIGUSR1, once the timer has expired, the zeek process spins at 100% CPU usage and the signal handler is not invoked anymore.

process.on('SIGUSR1', () => {
  console.log('Got SIGUSR1');
})

setTimeout(() => {
  console.log("timer");
}, 10000);
console.log("Ready");
$ zeek -B main-loop ./examples/signal.js exit_only_after_terminate=T
[ DEBUG ] Init: Node initialized. Compiled with v16.13.1
[ DEBUG ] Init: V8 initialized. Version 9.4.146.24-node.14
Ready
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
timer$ zeek ./examples/signal.js exit_only_after_terminate=T
[ DEBUG ] Init: Node initialized. Compiled with v16.13.1
[ DEBUG ] Init: V8 initialized. Version 9.4.146.24-node.14
Ready
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
Got SIGUSR1
timer
Got SIGUSR1

Got SIGUSR1

Looking at -B main-loop indicates the uv loop is always ready to be consumed.

Might be triggered by UV_RUN_NOWAIT that we're using currently?

@awelzel
Copy link
Collaborator Author

awelzel commented Apr 10, 2022

Hmm, nope. It's just that when the timer expires, the uv_loop isn't considered alive anymore and uv_run() doesn't actually process the signal handles.

Running a HTTP server or scheduling a timer again and again band-aids this.

This was initially observed when resizing the terminal which sends SIGWINCH and zeek would start spinning at 100% CPU.

@awelzel
Copy link
Collaborator Author

awelzel commented Apr 10, 2022

We could maybe manually uv_ref() signal handles when exit_only_after_terminate=T (or just always) to avoid this scenario.

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

1 participant