-
Notifications
You must be signed in to change notification settings - Fork 429
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
Fixed issue #643 and memory leak in hackney_pool #661
Conversation
@@ -127,8 +127,7 @@ do_checkout(Requester, Host, _Port, Transport, #client{options=Opts, | |||
{error, Reason} -> | |||
{error, Reason}; | |||
{'EXIT', {timeout, _}} -> | |||
% socket will still checkout so to avoid deadlock we send in a cancellation | |||
gen_server:cast(Pool, {checkout_cancel, Connection, RequestRef}), | |||
%% checkout should be canceled by the caller via hackney_manager |
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.
No need to cancel it here, as we now can rely on eventually caneling it by hackney_manager.
%------------------------------------------------------------------------------ | ||
%% @private | ||
%%------------------------------------------------------------------------------ | ||
del_from_queue(Connection, Ref, Queues) -> |
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 is not needed anymore. Moreover, there is remove_pending
which can be used instead and is implemented in a more efficient manner: first check pending
dict and (if found) filter queue
.
This is awesome, you have all but one test passing. |
Looks like the failed test (hackney_integration_tests:'-test_frees_manager_ets_when_body_is_in_client/0-fun-2-'/2 ) has a non-deterministic behavior, At least two reasons for it are as follows:
I think it's worth fixing this test, but it's not directly related to the issue. |
@benoitc @IceDragon200 I think we might have a solution here. |
@isaacsanders @SergeTuchiy I guess the last test is to run a request loop and see if it still experiences EDIT:
Looks like it works as intended, so 👍 I'll close my PR and reference this one |
do anyone else faced this issue on this PR.
|
@ijunaid8989 |
I have been using this branch in latest HTTPoison , and I am sending 500 per second post requests to a third party API. my code looks like this def post(url, file_path, image) do
HTTPoison.post(
url,
{:multipart, [{file_path, image, []}]},
[],
hackney: [pool: :seaweedfs_upload_pool, recv_timeout: 15_000]
)
end and I have these pool settings
in my application tree. |
@ijunaid8989
My code snippet:
This not introduced by this PR, as it's also reproducible on master. |
@SergeTupchiy Actually we are not making any HTTPS request, the origin of the request is HTTPS but the remote URL to which request is going is not HTTPs. do you still suggest the same? |
@ijunaid8989, You can add some logging there and share the output. It would help to locate the issue.
|
@SergeTupchiy we are actually trapped with many errors. checkout timeout, checkout failure, closed. |
@ijunaid8989, |
sorry for the late reply. I have been quite busy these days. Thanks for the patch! Looking at it. |
@benoitc Running into this issue currently. Any status update on your end? |
@benoitc Also getting bit hard by this, merging would be much appreciated so we don't have to further litter our codebase with catches and hard resets of the pool everytime we make a request with HTTPoison that may timeout. Thank you! |
@lasernite how do you hard reset your pool? |
@ijunaid8989 we're doing stuff like:
|
is it helpful? we also getting timeout/checkout_timeout/checkout_failure/closed? Would that be helpful in such condition? |
@ijunaid8989 Yeh once we catch the timeouts and reset the pool the error goes away—although I assume this has some negative performance implications as unnecessarily clearing the pool frequently, but nothing noticeable so far. |
Okay thanks. FYI: we have started hackney pools such as
in application.ex file. |
@ijunaid8989 Assuming those child_specs are getting started in a supervision tree in your application, I'm guessing you have to stop the pools by the atoms you customized above (:snapshot_pool, etc.) instead of :default when calling stop_pool. But don't take my word for it—I'm just using a library around hackney (HTTPoison) instead of accessing the methods directly like this, so I'll leave it up to you to see what works! |
Thanks, I am also using HTTPoison, but this is how we are starting the pools. can you tell me how you have started the pools? I mean in the config file? or with each HTTP request? Maybe your way of using pools with HTTPoison is different (correct).? |
@ijunaid8989 We're not setting up any custom pools. As HTTPoison is a dependency in mix.exs when we start the server the normal application lifecycle methods are hit to automatically start HTTPoison and add to the supervision tree. Pooling reduces latency on subsequent requests from the same host, but I haven't investigated whether our patch is stopping pooling altogether or whether when the pools get stopped the supervision tree is automatically restarting them again. Doesn't matter except for saving a few hundred milliseconds on subsequent requests in the best case, which if we are losing will be fixed when this library is updated and we remove the temporary patch. |
remove pending by the same ref that was taken from the front of the queue
Replace casting checkout_cancel msg in hackney_pool with a hackney_manager:cancel_request/1 call from hackney_connect: this must ensure that pool checkout is canceled as well as client state is erased
This is just to reformat my commit messages 😄 |
@SergeTupchiy You got me, I was thinking its a fix for something! |
late update but testing the patch right now. thanks for the refactoring |
It would be great to see some progress on this. I had to clone HTTPoison as well as Hackney to use my own sources. |
this release is beeing tested. It will be normally shipped later today. |
@SergeTupchiy thanks for the patch. Just merged your changes. Will finish the testing later today of the release today. Normally a release should land today as well. |
Is this now part of the 1.16.0 release? I'm also using my own sources and would like to switch back to official release but I keep getting the same issue. Thanks! |
this is part of the coming release yes. I will take care of it this
morning . Have been sidetracked until now
On Thu 26 Nov 2020 at 20:33 Raphaël Sfeir ***@***.***> wrote:
Is this now part of the 1.16.0 release? I'm also using my own sources and
would like to switch back to official release but I keep getting the same
issue. Thanks!
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#661 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAADRIVEOVWZ6NYYEWRMXHTSR2UPHANCNFSM4SPUB3IQ>
.
--
Sent from my Mobile
|
This version fixes a memory/connection pool leak that has resulted in app crashes on some of our other projects (and maybe this one?). ref: benoitc/hackney#661
This version fixes a memory/connection pool leak that has resulted in app crashes on some of our other projects (and maybe this one?). Since Hackney is not explicitly depended-on anywhere in `concierge_site` it can be removed from that app's dependencies entirely. ref: benoitc/hackney#661
This version fixes a memory/connection pool leak that has resulted in app crashes on some of our other projects (and maybe this one?). Since Hackney is not explicitly depended-on anywhere in `concierge_site` it can be removed from that app's dependencies entirely. ref: benoitc/hackney#661
This version fixes a memory/connection pool leak that has resulted in app crashes on some of our other projects (and maybe this one?). Since Hackney is not explicitly depended-on anywhere in `concierge_site` it can be removed from that app's dependencies entirely. ref: benoitc/hackney#661
Fixes: #643
This is similar to PR #656, but using
hackney_manager:cancel_request/1
ensures that request state is also erased from process dictionary and deleted fromhackney_manager_refs
ETS table.Additionally, this PR includes a memory leak fix (pending client not removed in
hackney_pool:dequeue
) and some code cleanup.