Skip to content

Commit

Permalink
BUG FIX: If a 'callr' future failed, because the parallel processed c…
Browse files Browse the repository at this point in the history
…rashed,

the corresponding parallel-worker slot was never released.
Related to HenrikBengtsson/future#677
  • Loading branch information
HenrikBengtsson committed Apr 19, 2023
1 parent c9a0906 commit 8ff6f1c
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
.test
.local
.make/
.Rdump/
*.o
*.dll
*.Rout
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: future.callr
Version: 0.8.1-9001
Version: 0.8.1-9002
Depends:
R (>= 3.4.0),
future (>= 1.23.0)
Expand Down
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Version (development version)

* ...
## Bug Fixes

* If a 'callr' future failed, because the parallel processed crashed,
the corresponding parallel-worker slot was never released.


# Version 0.8.1 [2022-12-13]
Expand Down
18 changes: 17 additions & 1 deletion R/CallrFuture-class.R
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,23 @@ await <- local({
## Failed?
if (inherits(result, "error")) {
msg <- post_mortem_failure(result, future = future)
stop(CallrFutureError(msg, future = future))
ex <- CallrFutureError(msg, future = future)

## Remove future from FutureRegistry?
if (!process$is_alive()) {
reg <- "workers-callr"
if (packageVersion("future") >= "1.32.0-9006") {
if (FutureRegistry(reg, action = "contains", future = future)) {
FutureRegistry(reg, action = "remove", future = future)
}
} else {
tryCatch({
FutureRegistry(reg, action = "remove", future = future)
}, error = identity)
}
}

stop(ex)
}

if (debug) mdebugf("- callr:::get_result() ... done (after %d attempts)", ii)
Expand Down
27 changes: 27 additions & 0 deletions tests/callr,worker-termination.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
source("incl/start.R")

message("*** callr() - terminating workers ...")

plan(callr, workers = 2L)

all <- nbrOfWorkers()
free <- nbrOfFreeWorkers()
stopifnot(
nbrOfWorkers() == 2L,
nbrOfFreeWorkers() == 2L
)

## Force R worker to quit
f <- future({ tools::pskill(pid = Sys.getpid()) })
res <- tryCatch(value(f), error = identity)
print(res)
stopifnot(inherits(res, "FutureError"))

stopifnot(
nbrOfWorkers() == all,
nbrOfFreeWorkers() == free
)

message("*** callr() - terminating workers ... DONE")

source("incl/end.R")

0 comments on commit 8ff6f1c

Please sign in to comment.