[Rd] system(timeout=) may timeout with 0 exit code

Jan Gorecki j@goreck| @end|ng |rom w|t@edu@p|
Thu May 14 20:34:35 CEST 2020


Hi R developers,

I observed that system(timeout=) may still return exit code 0, when
killing the process due to timeout.

In src/unix/sys-unix.c there is

#define KILL_SIGNAL1 SIGINT
#define KILL_SIGNAL2 SIGTERM
#define KILL_SIGNAL3 SIGKILL
#define EMERGENCY_TIMEOUT 20

After little bit of debugging I observed that total time of system
call is provided timeout value + 20s. That means EMERGENCY_TIMEOUT 20
kicked in, adding 20 seconds.

I don't have a reproducible example, but following code, and output
file below should be enough to ensure that there is a problem there
(exit code 0 despite timeout).

warn = NULL
p = proc.time()[[3L]]
tryCatch(
  ret <- system(cmd, timeout=timeout_s),
  warning = function(w) {
    warn <<- w[["message"]]
  }
)
if (length(warn) && ret==0L)
  cat(sprintf("command '%s' timed out(?) but still exited with 0 code,
timeout %ss, took %ss, warning '%s'\n",
              cmd, timeout_s, proc.time()[[3L]]-p, warn),
file="timeout-exit-codes.out", append=TRUE)

And the content of timeout-exit-codes.out:

command '/bin/bash -c "./_launcher/solution.R > log.out 2> log.err"'
timed out(?) but still exited with 0 code, timeout 7200s, took
7220.005s, warning '/bin/bash -c "./_launcher/solution.R > log.out 2>
log.err"' timed out after 7200s'

Thank you,
Jan Gorecki



More information about the R-devel mailing list