Skip to content
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

Merged
merged 3 commits into from Sep 10, 2018
Merged

(feat) Support 'checkout_timeout' option #520

merged 3 commits into from Sep 10, 2018

Conversation

leonardb
Copy link
Contributor

Allow caller to handle overload when pool is maxed out rather than returning
incorrect 'connection_timeout' response

Allow caller to handle overload when pool is maxed out rather than returning
incorrect 'connection_timeout' response
@@ -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),
Copy link
Owner

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?

Copy link
Contributor Author

@leonardb leonardb Sep 6, 2018

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

Copy link
Owner

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.

Copy link
Contributor Author

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} ->

@benoitc benoitc merged commit cf15810 into benoitc:master Sep 10, 2018
@benoitc
Copy link
Owner

benoitc commented Sep 10, 2018

Thanks! merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants