httr
httr copied to clipboard
curl handles in handle_pool become dead in package finalizer
When same urls are requested in some package functions and in package finalizer, curl handles cached in handle_pool
become "dead", because curl handle finalizers are run before package finalizer.
Here is a reprex (put in a package)
test <- function() httr::GET("https://www.google.com")
.onLoad <- function(x, y) {
reg.finalizer(environment(sys.function()), function(env) test(), TRUE)
test()
}
Right now I just call httr::handle_reset()
for each URL used in the finalizer, but I would prefer to have a more generic approach, because these URLs are called by some other packages internals and they may change in the future, breaking my package.
I think one of the following options could work:
- have an option to not maintain
handle_pool
at all - have a function
handle_pool_reset()
to clear the whole pool - update
httr::handle_find()
to check if the handle is not dead before returning it (will require newcurl::handle_is_dead()
function) - update
httr::handle_find()
to add its own finalizer that would remove the url from the pool before the handle is cleared by curl
I can submit a pool request :), just not sure which approach would be preferred.
Thanks, Oleh Khoma