How to force close `::Async::HTTP::Internet` instance without calling `response.read`
arseny-emchik opened this issue · comments
Hi! I make requests using ::Async::HTTP::Internet.new
. Everything works well until there is an error before reading the body of the response. So closing ::Async::HTTP::Internet
instance without calling response.read
leads to Waiting for Async::HTTP::Protocol::HTTP1 pool to drain: #<Async::Pool::Controller(1/∞) 1/1/1>
error which blocks the Fiber process (infinity loop I guess).
Question: Is there any way how to force close ::Async::HTTP::Internet
instance without calling .read
function?
Code example:
def make_get_request(url)
client_instance = ::Async::HTTP::Internet.new
response = client_instance.get(url)
raise "Any Error" # Any logic that can raise an exception
response.read
ensure
client_instance.close # Warning and Fiber process hanging => Waiting for Async::HTTP::Protocol::HTTP1 pool to drain: #<Async::Pool::Controller(1/∞) 1/1/1>
end
![Screenshot 2023-10-02 at 12 50 44](https://private-user-images.githubusercontent.com/5054656/271950766-e9a1e17d-2086-4748-8826-d9303b0e0764.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjQ2NDkwNjksIm5iZiI6MTcyNDY0ODc2OSwicGF0aCI6Ii81MDU0NjU2LzI3MTk1MDc2Ni1lOWExZTE3ZC0yMDg2LTQ3NDgtODgyNi1kOTMwM2IwZTA3NjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDgyNiUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA4MjZUMDUwNjA5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9YmZiMTFiYTViN2JjNWVkZmFkY2Y1ZDQ4MDA1MjIyZTk4NWZlZDFmYzgxY2JmN2Q3OWEyYmUzZWVkYjg5OWM5YiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.YY8xRV_MZ1ZG4QEnj2Qxz6dRR8Fqg1aRF4_Pjse9AwY)
Research:
The error happens here in the Async::Client#close function:
def close
while @pool.busy?
Console.logger.warn(self) { "Waiting for #{@protocol} pool to drain: #{@pool}" }
@pool.wait
end
@pool.close
end
I would appreciate any help! Thank you!
I think the simplest solution is to ensure you have
ensure
response&.close
client_instance&.close
@ioquatix Thank you for explaining how to do this! That works