elixir-mint / mint

Functional HTTP client for Elixir with support for HTTP/1 and HTTP/2 🌱
Apache License 2.0
1.36k stars 112 forks source link

`Mint.HTTP1` leaks socket upon receive timeout #415

Closed fercasgal closed 9 months ago

fercasgal commented 9 months ago

When there's a receive timeout, the Mint.HTTP1 simply does:

defp handle_error(conn, error) do
  conn = put_in(conn.state, :closed)
  {:error, conn, error, []}
end

But the socket is still open and the calling code has no chance of closing it, since:

def close(%MODULE{state: :closed} = conn) do
  {:ok, conn}
end

So the calling code believes that it has to open a new connection, and the previous one leaks.

whatyouhide commented 9 months ago

@fercasgal I pushed out #416, which should fix this. If we get into handle_error/2, it means that there was a transport error, and I think we assumed that that meant the socket was closed.

fercasgal commented 9 months ago

I tried your branch in our setup and it fixed the memory leak we were seeing.

whatyouhide commented 9 months ago

Fantastic! I've released v1.5.2.