rmyorston / busybox-w32

WIN32 native port of BusyBox.
https://frippery.org/busybox
Other
670 stars 124 forks source link

Imprecise timeout or sleep #400

Closed ale5000-git closed 1 month ago

ale5000-git commented 4 months ago

This works fine in the online bash shell: timeout 5.99 sleep 5.98; echo $? but on BusyBox it timeout.

I'm sure why but in the past I also get this to fail timeout 6 sleep 5; echo $? but now it works.

rmyorston commented 4 months ago

BusyBox timeout accepts fractional times but silently truncates them to an integer value. The example above is therefore effectively:

timeout 5 sleep 5.98; echo $?

The problem is in the upstream code so any fix will need to be acceptable to them.

ale5000-git commented 4 months ago

This also timeout: timeout 6 sleep 5.9; echo $?

rmyorston commented 4 months ago

This also timeout: timeout 6 sleep 5.9; echo $?

That one, I think, is my problem, so can be fixed without reference to upstream.

ale5000-git commented 4 months ago

Thanks, for the other one I will report it upstream when I get some time.

rmyorston commented 4 months ago

I've submitted a patch upstream. I've also fixed both the problems in busybox-w32.

The precision is still a bit off:

timeout 0.99 sleep 0.96; echo $?

sometimes fails and sometimes works. It's either inaccurate timekeeping or the slow process creation on Windows (so the timeout starts 10-20ms before the sleep). Possibly both.

Try the latest prerelease binaries (PRE-5320 or later).

ale5000-git commented 4 months ago

This works perfectly: timeout 5.99 sleep 5.95; echo $? It seems good enough for almost all uses, thanks a lot.

rmyorston commented 1 month ago

This issue should be fixed in the latest release, FRP-5398.

rmyorston commented 1 month ago

The upstream patch has also been applied, so fractional timeouts are supported there too now.