On 5/14/20 8:34 PM, Jan Gorecki wrote:
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).

Thanks for the report, but I can't tell from the report what the problem is, I would really need a reproducible example, and ideally one that uses only minimal/trivial child processes. I tried with such examples on my system, but they did not trigger the problem.

In this example, SIGINT succeeds in terminating the child process

> system.time(print(system("while /bin/true ; do /bin/true ; done", timeout=1)))
[1] 124
   user  system elapsed
  0.712   0.316   1.002

In this example, SIGTERM succeeds (after additional 20s)

> system.time(print(system("trap '' INT ; while /bin/true ; do /bin/true ; done", timeout=1)))
[1] 124
   user  system elapsed
 14.813   6.641  21.002

In this example, SIGKILL succeeds (after additional 40s)

> system.time(print(system("trap '' INT TERM ; while /bin/true ; do /bin/true ; done", timeout=1)))
[1] 124
   user  system elapsed
 29.075  12.918  41.002

In these examples, the execution time and the exit status is as documented in ?system.

Best
Tomas


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

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to