Skip to content

hackney >= 1.24 body already consumed on HTTP redirect + pool option #503

@arjan

Description

@arjan

benoitc/hackney@8f13dda#diff-5ca728a70e904304b3b9c49f7397cd28afdae5b779aa400fbee9301ace6b9cf9R1104-R1132

This commit fetches (and discards) the body of the request of redirect responses when custom :pool option is used, to overcome some kind of resource leak.

iex(8)> Mix.install([{:hackney, "== 1.24.0"}])
:ok
iex(9)> {:ok, 302, _, c} = :hackney.request("GET", "https://httpbin.org/redirect/2", [], "", [pool: :example])
{:ok, 302,
 [
   {"Date", "Wed, 15 Oct 2025 14:27:54 GMT"},
   {"Content-Type", "text/html; charset=utf-8"},
   {"Content-Length", "247"},
   {"Connection", "keep-alive"},
   {"Server", "gunicorn/19.9.0"},
   {"Location", "/relative-redirect/1"},
   {"Access-Control-Allow-Origin", "*"},
   {"Access-Control-Allow-Credentials", "true"}
 ], #Reference<0.2099663243.2053373956.249404>}
iex(10)> :hackney.body(c, 0)
{:error, :req_not_found}

I guess base.ex should be adjusted to also check for these response codes (in presence of the :pool option) in order to circumvent the :req_not_found error and just return the request w/ empty body? If you agree I'll create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions