GNU bug report logs - #77535
timeout treats very short durations as `0`

Previous Next

Package: coreutils;

Reported by: Nicolas Boichat <nicolas <at> boichat.ch>

Date: Fri, 4 Apr 2025 16:13:02 UTC

Severity: normal

Done: Pádraig Brady <P <at> draigBrady.com>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: help-debbugs <at> gnu.org (GNU bug Tracking System)
To: Pádraig Brady <P <at> draigBrady.com>
Cc: tracker <at> debbugs.gnu.org
Subject: bug#77535: closed (timeout treats very short durations as `0`)
Date: Fri, 04 Apr 2025 19:29:02 +0000
[Message part 1 (text/plain, inline)]
Your message dated Fri, 4 Apr 2025 20:27:55 +0100
with message-id <a1cfeefb-ca6d-42a5-8701-8e8c0d607b87 <at> draigBrady.com>
and subject line Re: bug#77535: timeout treats very short durations as `0`
has caused the debbugs.gnu.org bug report #77535,
regarding timeout treats very short durations as `0`
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)


-- 
77535: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=77535
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
From: Nicolas Boichat <nicolas <at> boichat.ch>
To: bug-coreutils <at> gnu.org
Subject: timeout treats very short durations as `0`
Date: Fri, 4 Apr 2025 17:26:56 +0200
Hi,

Version: timeout (GNU coreutils) 9.6, Archlinux, x86-64.

While playing with different duration parameters to `timeout`, I
noticed that extremely short durations, like `1e-3000`, are rounded
down to `0`. The problem is that `0` has a special meaning (disabling
the timeout), so I don't think this is desired.

All of these commands exit immediately:
```
timeout 0.0001 cat
timeout 1e-100 cat
timeout 1e-300 cat
timeout 1e-323 cat
```

But these never exits:
```
timeout 1e-324 cat
timeout 1e-3000 cat
```

As if we had typed:
```
timeout 0 cat
```

I think there is some logic in `printf` to handle float parsing
underflow, so maybe this can be reused in `timeout` as well.

Thanks,


[Message part 3 (message/rfc822, inline)]
From: Pádraig Brady <P <at> draigBrady.com>
To: Nicolas Boichat <nicolas <at> boichat.ch>, 77535-done <at> debbugs.gnu.org
Subject: Re: bug#77535: timeout treats very short durations as `0`
Date: Fri, 4 Apr 2025 20:27:55 +0100
On 04/04/2025 16:26, Nicolas Boichat wrote:
> Hi,
> 
> Version: timeout (GNU coreutils) 9.6, Archlinux, x86-64.
> 
> While playing with different duration parameters to `timeout`, I
> noticed that extremely short durations, like `1e-3000`, are rounded
> down to `0`. The problem is that `0` has a special meaning (disabling
> the timeout), so I don't think this is desired.
> 
> All of these commands exit immediately:
> ```
> timeout 0.0001 cat
> timeout 1e-100 cat
> timeout 1e-300 cat
> timeout 1e-323 cat
> ```
> 
> But these never exits:
> ```
> timeout 1e-324 cat
> timeout 1e-3000 cat
> ```
> 
> As if we had typed:
> ```
> timeout 0 cat
> ```
> 
> I think there is some logic in `printf` to handle float parsing
> underflow, so maybe this can be reused in `timeout` as well.

The following should avoid this issue.

Marking this as done.

thanks!
Pádraig

diff --git a/src/timeout.c b/src/timeout.c
index 578d71070..6756cd888 100644
--- a/src/timeout.c
+++ b/src/timeout.c
@@ -371,6 +371,10 @@ parse_duration (char const *str)
       usage (EXIT_CANCELED);
     }

+  /* Clamp underflow to 1ns, as 0 disables the timeout.  */
+  if (duration == 0 && errno == ERANGE)
+    duration = 1e-9;
+
   return duration;
 }



This bug report was last modified 42 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.