Skip to content

Commit

Permalink
Workaround for weird threading issue on Linux
Browse files Browse the repository at this point in the history
See #327
  • Loading branch information
jeroen committed Dec 7, 2023
1 parent a47d7f9 commit 710d1f9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Suggests:
testthat (>= 1.0.0),
knitr,
jsonlite,
later,
rmarkdown,
magrittr,
httpuv (>= 1.4.4),
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 5 additions & 2 deletions R/echo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand All @@ -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)
Expand Down

0 comments on commit 710d1f9

Please sign in to comment.