-
Notifications
You must be signed in to change notification settings - Fork 759
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
rc.initial infinite loop (+ fix) #1240
Comments
if the tty is closed while the script is running, it would previously go in an infinite loop trying to read from and write to the now-defunct tty. fixes: opnsense#1240
|
Hi @speed47, Thanks for the analysis! I will have to test if this reliably exits under all circumstances. Also, shouldn't we catch this inside the loop and exit 1 just to be safe? Cheers, |
|
maybe "set -e" works here too? |
|
I guess the shell should at least get a SIGHUP when it happens, so we could add a handler for that, didn't try it! |
|
@speed47 how about protecting the command lauchers with "|| true"? these are the ones that could fail, but that's ok from the "shell" perspective. In the far history of this code, the problem was that CTRL+C et al could allow escaping to a shell. In almost-far history the issue was we used this as a real shell so CTRL+C would log you out much to the annoyance of the user. |
|
|| true on all lines always sounds a bit like a "dirty" hack to me, but regarding CTRL+C and the history of the code, I understand why you feel set +e would be "safer". |
|
set +e or if $cmd; then :; fi possibilities are endless, but I agree they all look weird :D your suggestion to annotate with comments is probably in order whatever we do |
|
Yes :) Well |
|
Shall I propose a PR with what we've discussed, so we can start testing? |
|
If you want please do, otherwise just let me know to take over. :) |
if the tty is closed while the script is running, it would previously go in an infinite loop trying to read from and write to the now-defunct tty. fixes: opnsense#1240
if the tty is closed while the script is running, it would previously go in an infinite loop trying to read from and write to the now-defunct tty. fixes: opnsense#1240
I noticed that my up to date OPNsense was experiencing a constant loadavg of 8 after a few days of uptime without having any process in top eating cpu. The "last pid" indicator was however getting +10000 per /second/.
After some digging I found the culprit: a couple of lingering rc.initial processes (root's shell) from previous dead ssh connections were eating all cpu cycles.
Truss indicated that these processes were stuck in a loop trying to write to stdout, getting i/o errors, trying to read input from a closed stdin, and back again.
The fix is trivial: replace
while : ;By
while test -t 1 ;In the rc.initial script, which breaks the loop when stdout is closed (and we no longer have a tty).
How to reproduce:
The text was updated successfully, but these errors were encountered: