safe_sleep.sh: resolve reliability and maintainability issues#4465
Open
logiclrd wants to merge 1 commit into
Open
safe_sleep.sh: resolve reliability and maintainability issues#4465logiclrd wants to merge 1 commit into
logiclrd wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
As described in #185304, the
safe_sleep.shscript is problematic because it isn't clear exactly what problems it is solving or whether it is doing so correctly.This PR attempts to address this in the following ways:
sleepcannot be trusted. Additional logic has been added to detect ifsleepreturns immediately and fall through to a fallback strategy./bin/bashon the shebang and directly uses Bash-specific syntax no longer has a branch where it double-checks that it is running under Bash. That branch now also simply uses Bash features like the rest of the script.readverifies thatreadis abuiltinbefore attempting to use it to read from the shell process' standard streams.renices the shell it's running in to a lower priority.dateto could elapsed time instead of the Bash built-inSECONDSvariable, and it will now leverage the%Nformat specifier todateif it is supported by the host-supplieddateimplementation. This allows subsecond precision with the busy-wait. If subsecond precision isn't available, then it continues to loop with second-level precision, which means that the delay will be up to 1 second shorter than requested, depending on how far into the first second the wait was initiated (average 0.5 seconds shorter than requested).These paths have been tested on modern Linux systems, on Linux hosted on WSL 1, and with Bash 3.2.57 running on FreeBSD.
Closes: #185304