From 710d1f9949bc05bd738a41e71775c4db4676202e Mon Sep 17 00:00:00 2001 From: Jeroen Ooms Date: Thu, 7 Dec 2023 19:34:39 +0100 Subject: [PATCH] Workaround for weird threading issue on Linux See #327 --- DESCRIPTION | 1 + NEWS | 1 + R/echo.R | 7 +++++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7589b9a4..dc3e2fc9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -27,6 +27,7 @@ Suggests: testthat (>= 1.0.0), knitr, jsonlite, + later, rmarkdown, magrittr, httpuv (>= 1.4.4), diff --git a/NEWS b/NEWS index 5be4440c..ca33b30c 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ 5.2.0 - The CURL_CA_BUNDLE envvar is now also used on non-Windows. - curl_echo() now uses a random available port to run httpuv + - Add workaround for slowness in curl_echo() on Linux - Fix a few printf format warnings 5.1.0 diff --git a/R/echo.R b/R/echo.R index 3ef8cf9b..4b0f0140 100644 --- a/R/echo.R +++ b/R/echo.R @@ -65,6 +65,10 @@ curl_echo <- function(handle, port = find_port(), progress = interactive(), file # Workaround bug in httpuv on windows that keeps protecting handler until next startServer() on.exit(rm(handle), add = TRUE) + # Workaround for weird threading issue on Linux + # See: https://github.com/jeroen/curl/issues/327 + wait <- ifelse(isTRUE(grepl('linux', R.version$platform)), 0.001, 0) + # Post data from curl xfer <- function(down, up){ if(progress){ @@ -75,8 +79,7 @@ curl_echo <- function(handle, port = find_port(), progress = interactive(), file as.integer(100 * up[2] / up[1])), file = stderr()) } } - # Need very low wait to prevent gridlocking! - httpuv::service(NA) + later::run_now(wait) TRUE } handle_setopt(handle, connecttimeout = 2, xferinfofunction = xfer, noprogress = FALSE, forbid_reuse = TRUE)