Closed maxsutton closed 2 months ago
Slightly simpler reprex:
library(httr2)
temp <- tempfile()
writeLines("Hello, world!", temp)
# OK
reqs <- lapply(1:129, function(i) request(example_url()))
parallel <- req_perform_parallel(reqs, on_error = "continue")
# NOT OK
reqs <- lapply(1:129, function(i) request(example_url()) |> req_body_file(temp))
parallel <- req_perform_parallel(reqs, on_error = "continue")
So I'm holding on to connections somewhere in the path way that serves the file.
...
Hmmm, I bet this is it:
con <- file(data, "rb")
# Leaks connection if request doesn't complete
So I'll need to think of a better way to clean up the connection created here.
Maybe req_body_apply()
needs to include some callback that will close the open connection? And then maybe give req_handle()
some sort of done()
callback which we can call from $suceed()
and req_perform()
?
...
Hmmm, it must be more complicated than that because I do see the correct close
function getting called.
...
Ooooh, the problem is that we're opening the connection when we register the call, but we only close it when it's done.
Thanks @hadley! I didn't have the headspace to dig into the package -- I've only just started to use it. So I really appreciated you sharing your thought process. Immensely helpful.
When uploading more than 128 files, req_perform_parallel fails with an error message:
This occurs even when restricting the curl pool to only use 2 connections at once.
It seems that httr2 opens some files by itself (such as by checking
utils::packageVersion("httr2")
, so the real limitation is more like 124 files. I have tested the same setup below usingreq_perform_sequential()
and it succeeds.Code
Note: With an endpoint of
example_url()
, a good request fails with an HTTP 404 error, but req_perform_parallel continues. When using more than 128 files, the error occurs before the first request is initiated, so the endpoint isn't a concern.Good (and expected behaviour)
Expected output: a progress bar and no errors.
small
andgood
are lists of the status of the requests made.Bug