Skip to content

Close TCP sockets on errors in HTTP/1 - #502

Open
xxdavid wants to merge 1 commit into
elixir-mint:mainfrom
xxdavid:close_sockets_on_error
Open

Close TCP sockets on errors in HTTP/1#502
xxdavid wants to merge 1 commit into
elixir-mint:mainfrom
xxdavid:close_sockets_on_error

Conversation

@xxdavid

@xxdavid xxdavid commented Sep 4, 2026

Copy link
Copy Markdown

In some cases, when handling a failure, Mint would only set the conn state to :closed but would not close the underlying socket. These sockets stay open until the calling process that owns them exits, and may therefore accumulate until resources are exhausted.

Every relevant %{conn | state: :closed} inside Mint.HTTP1 is replaced with internal_close that in addition to setting the state also closes the socket.

Tests that asserted closed conn now also assert that the socket is closed. New tests that demonstrate the problem are added. They would fail without the fix and they pass with the fix in place.

Fixes #501.

In some cases, when handling a failure, Mint would only set the conn
state to :closed but would not close the underlying socket. These
sockets stay open until the calling process that owns them exits, and
may therefore accumulate until resources are exhausted.

Every relevant %{conn | state: :closed} inside Mint.HTTP1 is replaced
with internal_close that in addition to setting the state also closes
the socket.

Tests that asserted closed conn now also assert that the socket is
closed. New tests that demonstrate the problem are added. They would
fail without the fix and they pass with the fix in place.

Fixes elixir-mint#501.

@whatyouhide whatyouhide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lovely!

@whatyouhide

Copy link
Copy Markdown
Contributor

@xxdavid can you look at the Dialyzer failure in CI?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TCP sockets get leaked on certain failures

2 participants