New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(feat) Support 'checkout_timeout' option #520
Conversation
Allow caller to handle overload when pool is maxed out rather than returning incorrect 'connection_timeout' response
src/hackney_pool.erl
Outdated
@@ -67,9 +67,9 @@ checkout(Host0, Port, Transport, #client{options=Opts}=Client) -> | |||
RequestRef = Client#client.request_ref, | |||
Name = proplists:get_value(pool, Opts, default), | |||
Pool = find_pool(Name, Opts), | |||
ConnectTimeout = proplists:get_value(connect_timeout, Opts, 8000), | |||
CheckoutTimeout = proplists:get_value(checkout_timeout, Opts, 8000), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this introduce a breaking change. I would rather add for the current version add support for both options, that may have a different meaning later or be deprecated. Can you do the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benoitc Sorry for delay, was on vacation. As I read it does support both options
with the change. Unless you're wanting to fall back through the options should checkout_timeout
not be defined.
IE
checkout_timeout -> connect_timeout -> default 8000
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant to fallback for now. ie if connect_timeout is set using it as checkout_timeout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I was proposing is to fall back to connect_timeout
when checkout_timeout
is not set.
If we do it the other way around checkout_timeout
would not be used when set and the desired separation of connect/checkout would not exist
diff --git a/src/hackney_pool.erl b/src/hackney_pool.erl
index ceb97a9..599fcf5 100644
--- a/src/hackney_pool.erl
+++ b/src/hackney_pool.erl
@@ -67,7 +67,9 @@ checkout(Host0, Port, Transport, #client{options=Opts}=Client) ->
RequestRef = Client#client.request_ref,
Name = proplists:get_value(pool, Opts, default),
Pool = find_pool(Name, Opts),
- CheckoutTimeout = proplists:get_value(checkout_timeout, Opts, 8000),
+ ConnectTimeout = proplists:get_value(connect_timeout, Opts, 8000),
+ %% Fall back to using connect_timeout if checkout_timeout is not set
+ CheckoutTimeout = proplists:get_value(checkout_timeout, Opts, ConnectTimeout),
case catch gen_server:call(Pool, {checkout, {Host, Port, Transport},
Pid, RequestRef}, CheckoutTimeout) of
{ok, Socket, Owner} ->
Thanks! merged :) |
Allow caller to handle overload when pool is maxed out rather than returning
incorrect 'connection_timeout' response