Skip to content

Remove multicore worker if process crashed #677

Closed

Description

@HenrikBengtsson

Issue

If a multicore future terminates the underlying forked R process, then
it occupies one of the worker slots.

Example:

library(future)

plan(multicore, workers = 4)
stopifnot(nbrOfWorkers() == 4)
stopifnot(nbrOfFreeWorkers() == 4)

f <- future({ Sys.sleep(2) })
stopifnot(nbrOfWorkers() == 4)
stopifnot(nbrOfFreeWorkers() == 3)

v <- value(f)
stopifnot(nbrOfWorkers() == 4)
stopifnot(nbrOfFreeWorkers() == 4)

f <- future({ tools::pskill(Sys.getpid()) })
stopifnot(nbrOfWorkers() == 4)
stopifnot(nbrOfFreeWorkers() == 3)

res <- tryCatch({
  v <- value(f)
}, error = identity)
stopifnot(inherits(res, "FutureError"))
conditionMessage(res)

## [1] "Failed to retrieve the result of MulticoreFuture (<none>) 
## from the forked worker (on localhost; PID 1632517). Post-mortem
## diagnostic: No process exists with this PID, i.e. the forked 
## localhost worker is no longer alive"

stopifnot(nbrOfWorkers() == 4)
stopifnot(nbrOfFreeWorkers() == 4)  ## FAIL; here we're stuck as 3

Suggestion

Detect when forked process is terminated (cf. post-mortem analysis), and remove the corresponding MulticoreFuture from the internal FutureRegistry to free up the slot.

This should be safe to do for multicore futures, because they're transient R processes.

Activity

  1. added this to the Next release milestone on Apr 18, 2023
  2. HenrikBengtsson commented on Apr 19, 2023

    @HenrikBengtsson
    CollaboratorAuthor

    Implemented; a "crashed" multicore future is now fully released making its "slot" available again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions