Skip to content

scripts: improve panic helpers#3155

Merged
georglauterbach merged 3 commits intomasterfrom
scripts/improve-panic
Mar 6, 2023
Merged

scripts: improve panic helpers#3155
georglauterbach merged 3 commits intomasterfrom
scripts/improve-panic

Conversation

@georglauterbach
Copy link
Copy Markdown
Member

Description

_shutdown wil now wait for Supervisord by default. Added option to exit immedaitely though. Adjusted panic handlers; made them more coherent and added one more panic type.

Fixes #3140

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Improvement (non-breaking change that does improve existing functionality)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

An additonal argument can now be given to `_shutdown` to indicate
immediate exit. The default has been changed to just wait for Supervisor
to kill all processes (which fixes #3140).

The panic handlers were adjusted accordingly and they now follow our
naming convention.
They were replaced by the `_dms_panic__*` handlers, and where I deemed
it safe, I added the `immediate` argument so we can shutdown fast.
@georglauterbach georglauterbach added area/scripts kind/improvement Improve an existing feature, configuration file or the documentation kind/bugfix labels Mar 5, 2023
@georglauterbach georglauterbach added this to the v12.0.0 milestone Mar 5, 2023
@georglauterbach georglauterbach self-assigned this Mar 5, 2023
@casperklein
Copy link
Copy Markdown
Member

Remember, when we once had the styling discussion? I wasn't a fan of putting everything in functions, even when they are only called once. This is the downside of it - the need for subshells to assign values 😉

But I have to admit, that I started liking it 😆

Copy link
Copy Markdown
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to use a different approach and not think about the arg dance, or if blocking is important inverting the arg opt-in.

Feel free to merge if you disagree 👍

Comment on lines +88 to +97
if [[ ${2:-wait} == 'immediate' ]]
then
# In case the user requested an immediate exit, he ensure he is not in a subshell
# call and exiting the whole script is safe. This way, we make the shutdown quicker.
exit 1
else
# We can simply wait until Supervisord has terminated all processes; this way,
# we do not return from a subshell call and continue as if nothing happened.
sleep 1000
fi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it not be cleaner to approach with the first panic call (_shutdown() rather) creating some state like /tmp/panic, and just checking if this file exists to block with the sleep 1000?

No need for the immediate arg then, which avoids calls with empty arg before it for scope.

At least that seems simpler and pretty much always the behaviour desired? (exit 1 first call, any subsequent calls block)

In the cited failure case, the log should stop where it expected from the looks of it.

I understand the drawback would be scripts continue to run after the first exit 1? But I don't quite understand how that exit 1 interacts with the scope of the ssl.sh helper, these are all panic calls within the same method, so what happens if sleep 1000 was at the end of the panic call? It always hits the sleep 1000?

We are avoiding the immediate arg only for ssl.sh and dns.sh, if keeping the arg approach, it may be simpler to invert this arg to opt-in to blocking instead?

Copy link
Copy Markdown
Member Author

@georglauterbach georglauterbach Mar 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose not to take the file approach because I really dislike scripts continuing after _shutdown was called (potentially causing behaviour we do not expect at all). I would definitely avoid going down UB-lane.

This is also the reason for the arg dance; using sleep is the conservative but also very safe method. Hence, it should be the default. I am not a big fan of '' args either, but it's working fine.

I'd keep it as is for now. If we ever feel the need to tackle this again, I will assist.

@georglauterbach
Copy link
Copy Markdown
Member Author

It might make sense to use a different approach and not think about the arg dance, or if blocking is important inverting the arg opt-in.

I provided feedback to your comment :) Hope that helps in explaining my choices.

Feel free to merge if you disagree 👍

I think this is fine for now :)

@georglauterbach georglauterbach merged commit dab7070 into master Mar 6, 2023
@georglauterbach georglauterbach deleted the scripts/improve-panic branch March 6, 2023 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/scripts kind/improvement Improve an existing feature, configuration file or the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] _shutdown will continue when called in a subshell (causing UB)

3 participants