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

DietPi-Update | G_ERROR_HANDLER does not exit script on error #3127

Closed
MichaIng opened this issue Sep 26, 2019 · 1 comment
Closed

DietPi-Update | G_ERROR_HANDLER does not exit script on error #3127

MichaIng opened this issue Sep 26, 2019 · 1 comment
Labels
Bug 🐞 Solution available 🥂 Definite solution has been done
Milestone

Comments

@MichaIng
Copy link
Owner

On e.g. G_AGUP or G_AGUG error or some download error or similar, dietpi-update continues instead of exiting.

Investigating the issue, I recognised that kill -INT $$ runs with correct argument (dietpi-update script PID), but is simply ignored. Some test shows that this is always the case when piping the output of a function and trying to kill the script from within the function:

root@DietPi:/tmp# cat test
#!/bin/bash
func(){
        echo started func $$
        kill -INT $$
        echo failed to kill func $$
}
echo started script $$
func | tee
echo failed to kill script $$
root@DietPi:/tmp# ./test
started script 3001
started func 3001
failed to kill func 3001
failed to kill script 3001

Some search about this: https://stackoverflow.com/questions/45303270/bash-redirect-vs-pipe

  • But in this mention case, the kill attempt is done from within the pipe target, where it makes sense to me, but in our case the kill attempt is done from within the pipe origin.

Redirection, even of both streams, does not have this issue:

root@DietPi:/tmp# cat test
#!/bin/bash
func(){
        echo started func $$
        kill -INT $$
        echo failed to kill func $$
}
echo started script $$
func &> >(tee)
echo failed to kill script $$
root@DietPi:/tmp# ./test
started script 3006

root@DietPi:/tmp# started func 3006

But not only the syntax looks a bid ugly, but also the output shows that the originating script does not wait for the subshell to finish:

root@DietPi:/tmp# echo 1 &> >(tee); echo 2
2
root@DietPi:/tmp# 1

This can be worked around with a wait:

root@DietPi:/tmp# echo 1 &> >(tee); wait $!; echo 2
1
2

While running tests I was first surprised that redirection to subshell seems to be MUCH faster then piping:

root@VM-Stretch:~# time for i in {1..1000}; do printf '' 2>&1 | tee; done

real    0m2.934s
user    0m0.048s
sys     0m0.564s
root@VM-Stretch:~# time for i in {1..1000}; do printf '' &> >(tee); done

real    0m1.029s
user    0m0.132s
sys     0m0.576s

However this is indeed only due to loop not waiting for tee:

root@VM-Stretch:~# time for i in {1..1000}; do printf '' &> >(tee); wait $!; done

real    0m2.998s
user    0m0.096s
sys     0m0.428s

And suddenly we are VERY close to the speed of piping 😉.

The bug is a regression from v6.25: 4285af6#diff-c613a85da508fb885b67c34f9661e243
Currently I see no chance then restoring the bid uncommon redirection of pre-v6.25. Seems like @Fourdee had some good reason to implement it like this and we need to keep this in mind whenever piping an error handled functions output.

@MichaIng MichaIng added Bug 🐞 Solution available 🥂 Definite solution has been done labels Sep 26, 2019
@MichaIng MichaIng added this to the v6.26 milestone Sep 26, 2019
MichaIng added a commit that referenced this issue Sep 26, 2019
+ DietPi-Update | Log update output to file by redirecting to subshell instead of piping, else G_ERROR_HANDLER cannot exit the script via "kill -INT $$": #3127
+ DietPi-Update | Minor coding and adding some info comments
@MichaIng
Copy link
Owner Author

MichaIng commented Sep 26, 2019

Fixed with: 1e52d13
Changelog: a3c8cf0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🐞 Solution available 🥂 Definite solution has been done
Projects
None yet
Development

No branches or pull requests

1 participant