Skip to content

Commit 58e1189

Browse files
authored
Fix potential error when worker process crashes (#2266)
Reading the output might fail, so we need to `tryCatch()` it. Closes #2262.
1 parent e4b98d5 commit 58e1189

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

R/parallel-taskq.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,14 @@ task_q <- R6::R6Class(
8888
pr[[i]][["error"]] == "ready"
8989
outmsg <- NULL
9090
if (has_output) {
91-
lns <- c(worker$read_output_lines(), worker$read_error_lines())
92-
inc <- paste0(worker$read_output(), worker$read_error())
91+
lns <- c(
92+
safely(worker$read_output_lines(), character()),
93+
safely(worker$read_error_lines(), character())
94+
)
95+
inc <- paste0(
96+
safely(worker$read_output(), ""),
97+
safely(worker$read_error(), "")
98+
)
9399
if (nchar(inc)) {
94100
lns <- c(lns, strsplit(inc, "\n", fixed = TRUE)[[1]])
95101
}
@@ -249,4 +255,11 @@ df_add_row <- function(df, ..., .before = NULL) {
249255
}
250256
}
251257

258+
safely <- function(expr, default = NULL) {
259+
tryCatch(
260+
expr,
261+
error = function(e) default
262+
)
263+
}
264+
252265
silence_r_cmd_check <- function() callr::r_session

0 commit comments

Comments
 (0)