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

Mint.HTTP1 leaks socket upon receive timeout #415

Closed
fercasgal opened this issue Dec 8, 2023 · 3 comments · Fixed by #416
Closed

Mint.HTTP1 leaks socket upon receive timeout #415

fercasgal opened this issue Dec 8, 2023 · 3 comments · Fixed by #416
Labels

Comments

@fercasgal
Copy link

fercasgal commented Dec 8, 2023

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 whatyouhide changed the title Mint.HTTP1 leaks socket upon receive timeout Mint.HTTP1 leaks socket upon receive timeout Dec 8, 2023
whatyouhide added a commit that referenced this issue Dec 8, 2023
@whatyouhide
Copy link
Contributor

@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
Copy link
Author

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

@whatyouhide
Copy link
Contributor

Fantastic! I've released v1.5.2.

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

Successfully merging a pull request may close this issue.

2 participants