Skip to content

Return a tunnel timeout error when the CONNECT deadline elapses#495

Merged
ericmj merged 1 commit into
mainfrom
clamp-tunnel-timeout
Jul 21, 2026
Merged

Return a tunnel timeout error when the CONNECT deadline elapses#495
ericmj merged 1 commit into
mainfrom
clamp-tunnel-timeout

Conversation

@ericmj

@ericmj ericmj commented Jul 21, 2026

Copy link
Copy Markdown
Member

A proxy that dribbles the CONNECT response until the tunnel deadline passes mid-loop makes receive_response/3 compute a negative timeout for its after clause, which raises ErlangError :timeout_value in the calling process instead of returning {:error, %Mint.HTTPError{reason: {:proxy, :tunnel_timeout}}}. This clamps the timeout to 0 so an elapsed deadline yields the documented error, with offline regression tests (the crash reproduces deterministically with an already-elapsed deadline).

Also documents :tunnel_timeout in the Proxying section, which was previously only mentioned in the Mint.HTTPError docs.

receive_response/3 recomputes the remaining timeout from the deadline on
every loop iteration and feeds it straight into the receive's after
clause. A proxy that keeps dribbling bytes of the CONNECT response until
the deadline passes mid-loop produces a negative timeout, which raises
ErlangError :timeout_value in the calling process instead of returning
{:error, %Mint.HTTPError{reason: {:proxy, :tunnel_timeout}}}. Clamp the
timeout to 0 so an elapsed deadline yields the documented error.

Also document the :tunnel_timeout option in the Proxying section; it was
previously only mentioned in the Mint.HTTPError docs.
@coveralls

coveralls commented Jul 21, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 0

Coverage increased (+0.06%) to 87.945%

Details

  • Coverage increased (+0.06%) from the base build.
  • Patch coverage: 1 of 1 lines across 1 file are fully covered (100%).
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 1659
Covered Lines: 1459
Line Coverage: 87.94%
Coverage Strength: 987.49 hits per line

💛 - Coveralls

Comment thread lib/mint/http.ex
* `:tunnel_timeout` - the maximum time (in milliseconds) to wait for the proxy
to reply to the `CONNECT` request. If the tunnel is not established within
this time, `connect/4` returns a `Mint.HTTPError` with reason
`{:proxy, :tunnel_timeout}`. Defaults to `30_000` (30 seconds).

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.

This is missing the *Available since vX.X.X* notice.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This option has been available since 0.1.0, it was just not documented.

@ericmj
ericmj force-pushed the clamp-tunnel-timeout branch from 82ad410 to 0bfc146 Compare July 21, 2026 16:02
@ericmj
ericmj merged commit bc24618 into main Jul 21, 2026
6 checks passed
@ericmj
ericmj deleted the clamp-tunnel-timeout branch July 21, 2026 16:05
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.

3 participants