Skip to content

Update safe_sleep.sh for bug when scheduler is paused for more than 1 second - #3157

Merged
ericsciple merged 1 commit into
actions:mainfrom
horner:patch-1
Aug 20, 2025
Merged

Update safe_sleep.sh for bug when scheduler is paused for more than 1 second#3157
ericsciple merged 1 commit into
actions:mainfrom
horner:patch-1

Conversation

@horner

@horner horner commented Feb 17, 2024

Copy link
Copy Markdown
Contributor

fixed a rare condition where the comparison may not be made within the second and then this will loop forever (or at least until a rollover of SECONDS) ;-)

sleep was replaced in #1707

But if safe_sleep.sh is running when a vm is suspended it will not do the comparison within the second and therefore loops forever when the vm is resumed.

@horner
horner requested a review from a team as a code owner February 17, 2024 16:38
@horner

horner commented Feb 17, 2024

Copy link
Copy Markdown
Contributor Author
Screenshot 2024-02-17 at 11 19 18 AM

@ericsciple
ericsciple enabled auto-merge (squash) August 20, 2025 18:40
@ericsciple
ericsciple disabled auto-merge August 20, 2025 18:47
@ericsciple
ericsciple enabled auto-merge (squash) August 20, 2025 18:47
fixed a rare condition where the comparison may not be made within the second and then this will loop forever (or at least until a rollover of SECONDS)  ;-)
@ericsciple
ericsciple merged commit 20d82ad into actions:main Aug 20, 2025
9 checks passed
@andrewrk

Copy link
Copy Markdown

fixed a rare condition

I assume you mean "rare" as in, "not finished cooking" because it happens all the damn time

@paralin

paralin commented Nov 29, 2025

Copy link
Copy Markdown

Is looping infinitely really an effective sleep?

@AXDOOMER

Copy link
Copy Markdown

Why are they not using the sleep command?

@NicolasDorier

NicolasDorier commented Dec 8, 2025

Copy link
Copy Markdown

I would suggest to just use sleep if available instead of doing something as extremely inefficient as that just so the 0.0001% of systems who doesn't have sleep can work.

Or better, just drop a sleep script in the PATH of the systems not supporting sleep by default... This might literally saves us from climate change.

@bybatkhuu

bybatkhuu commented Dec 10, 2025

Copy link
Copy Markdown

Came from "primeagen" content, holys**t it's real???
WOW!

@symmetricalbyte

Copy link
Copy Markdown

“A remarkable demonstration of how far one can stretch the boundaries of conventional engineering wisdom.”

@jcastrence

Copy link
Copy Markdown

Ironically named "safe_sleep.sh" 😭

Technically, I guess it is safer to simply not run your code at all.

@Rudxain

Rudxain commented Dec 10, 2025

Copy link
Copy Markdown

Sadly, this is now vulnerable to code-injection (see SC issue), because != is a string comparison and -lt is a numeric comparison

Bash is taking inspiration from PHP's insanity

@latekvo

latekvo commented Dec 10, 2025

Copy link
Copy Markdown

@Rudxain nice catch, I tested it on my end, and it actually allows for RCE

But as far as I see, safe_sleep.sh is never used with user input, so I don't think it's that serious. Still should be fixed in case it's exposed to the user in the future though.

@ngxson

ngxson commented Dec 10, 2025

Copy link
Copy Markdown
read -t $1

No external program needed

@andrzejsokolowski

Copy link
Copy Markdown

Doesn't this still take up an entire core of a CPU? Is this malicious code designed to waste as much processor compute time? Isn't this running this comparison billions of times a second? As other people pointed out in this thread, why not use sleep or other alternatives?

@pasabanov

Copy link
Copy Markdown

Isn't this running this comparison billions of times a second?

Not billions - bash is not that fast, but probably millions.
This still takes up an entire thread of the CPU.

why not use sleep or other alternatives?

This is a reasonable question. They previously had code that checked for programs like sleep or ping to use them if available, but they replaced it with this abomination.

@whoreson

Copy link
Copy Markdown

put me in the screenshot

@lachesis

Copy link
Copy Markdown

Under what circumstance is sleep actually not available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.