From b93964d861090ba4afe52e84f1911bb1431d236c Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:47:24 +0100 Subject: [PATCH 1/4] Ignore files --- .Rbuildignore | 1 + .gitignore | 2 ++ 2 files changed, 3 insertions(+) diff --git a/.Rbuildignore b/.Rbuildignore index 91db9e4fc..d2878597d 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -12,3 +12,4 @@ ^[\.]?air\.toml$ ^\.vscode$ ^cran-comments\.md$ +^CLAUDE.md$ diff --git a/.gitignore b/.gitignore index 66b308857..8e7afe64f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ inst/doc .vscode air.toml revdep/ +CLAUDE.md +.DS_Store From 0bb6937e52426d7fa5fea0506c106daa5a908396 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:47:34 +0100 Subject: [PATCH 2/4] Relax tests --- tests/tests.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/tests.R b/tests/tests.R index dc7746e0b..95dbf8227 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -25,12 +25,12 @@ test_error(mirai(), "missing expression, perhaps wrap in {}?") test_error(mirai(a, 1), "all `...` arguments must be named") test_error(mirai(a, .args = list(1)), "all items in `.args` must be named") test_error(mirai_map(1:2, identity)) -test_error(daemons(url = "URL"), "Invalid argument") +test_error(daemons(url = "URL")) test_error(daemons(-1), "zero or greater") test_error(daemons(raw(0L)), "must be numeric") test_error(daemons(1, dispatcher = "")) test_error(daemons(url = local_url(), dispatcher = NA)) -test_error(daemon("URL"), "Invalid argument") +test_error(daemon("URL")) test_error(launch_local(1L), "daemons must be set") test_error(race_mirai(list()), "daemons must be set") test_false(daemons_set()) From 30ad46e50071230a7179917ff999fe6844839b25 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:57:45 +0100 Subject: [PATCH 3/4] Refactor internal `sub_real_port()` --- R/daemons.R | 18 ++++++++++++------ R/dispatcher.R | 6 +----- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/R/daemons.R b/R/daemons.R index 27b0d41c4..6fa949066 100644 --- a/R/daemons.R +++ b/R/daemons.R @@ -790,15 +790,21 @@ launch_daemons <- function(seq, dots, envir) { pipe_notify(sock, NULL, add = TRUE) } -sub_real_port <- function(port, url) sub("(?<=:)0(?![^/])", port, url, perl = TRUE) +sub_real_port <- function(sock, url) { + if (parse_url(url)[["port"]] == "0") { + url <- sub( + "(?<=:)0(?![^/])", + opt(attr(sock, "listener")[[1L]], "tcp-bound-port"), + url, + perl = TRUE + ) + } + url +} create_sock <- function(envir, url, tls) { sock <- req_socket(url, tls = tls) - listener <- attr(sock, "listener")[[1L]] - url <- opt(listener, "url") - if (parse_url(url)[["port"]] == "0") { - url <- sub_real_port(opt(listener, "tcp-bound-port"), url) - } + url <- sub_real_port(sock, url) `[[<-`(envir, "cv", cv()) `[[<-`(envir, "sock", sock) `[[<-`(envir, "url", url) diff --git a/R/dispatcher.R b/R/dispatcher.R index 81a4e4acd..2e4f60403 100644 --- a/R/dispatcher.R +++ b/R/dispatcher.R @@ -81,11 +81,7 @@ dispatcher <- function(host, url = NULL, n = 0L, ...) { } } else { listen(psock, url = url, tls = tls, fail = 2L) - listener <- attr(psock, "listener")[[1L]] - url <- opt(listener, "url") - if (parse_url(url)[["port"]] == "0") { - url <- sub_real_port(opt(listener, "tcp-bound-port"), url) - } + url <- sub_real_port(psock, url) } send(sock, url, mode = 2L, block = TRUE) From 6199fa58a682b14846a1ab788301b8be82416298 Mon Sep 17 00:00:00 2001 From: shikokuchuo <53399081+shikokuchuo@users.noreply.github.com> Date: Wed, 15 Oct 2025 20:49:46 +0100 Subject: [PATCH 4/4] Cater for possible changes in `stop_aio()` error code --- tests/tests.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/tests.R b/tests/tests.R index 95dbf8227..f2e7942b5 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -389,13 +389,13 @@ connection && Sys.getenv("NOT_CRAN") == "true" && { Sys.sleep(0.1) test_true(stop_mirai(m2)) test_true(stop_mirai(m1)) - test_equal(m2$data, 20L) - test_equal(m1$data, 20L) + test_true(m2$data >= 20L) + test_true(m1$data >= 20L) test_class("errorValue", mirai(res)[]) m <- mirai_map(1:10, function(x) { Sys.sleep(2); y <<- TRUE }) Sys.sleep(0.1) s <- stop_mirai(m) - test_equal(sum(unlist(m[])), 200L) + test_true(all(m[] >= 20L)) test_class("errorValue", mirai(y)[]) test_identical(s, !logical(10L)) test_equal(status()$connections, 1L)