edgurgel / edgurgel/httpoison

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

Open
#503 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Elixir
Stars
2.3k
Forks
349
PR merge metrics
No merged PRs in 30d

Description

https://github.com/benoitc/hackney/commit/8f13ddac50d1626f8b9a47a08bd599e4efe1773d#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](https://github.com/edgurgel/httpoison/blob/main/lib/httpoison/base.ex#L899) 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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with lib/httpoison/base.ex around line 899 and reproduce the reported behavior using Mix.install with hackney 1.24.0, a redirect URL, and the :pool option. Compare handling of the redirect response and body access; done means the request can be returned with an empty body instead of producing :req_not_found.

Written by the indexing model from the issue text.

Assessment

Tech stack
elixir
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.