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

HTTP 407 error formatting when using proxies #439

Open
jozuas opened this issue Jun 26, 2024 · 6 comments
Open

HTTP 407 error formatting when using proxies #439

jozuas opened this issue Jun 26, 2024 · 6 comments

Comments

@jozuas
Copy link

jozuas commented Jun 26, 2024

Observed log:

** (Mint.HTTPError) expected tunnel proxy to return a status between 200 and 299, got: 407

Mint source code:

"expected tunnel proxy to return a status between 200 and 299, got: #{inspect(status)}"

From MDN HTTP 407:

The HTTP 407 Proxy Authentication Required client error status response code indicates that the request has not been applied because it lacks valid authentication credentials for a proxy server that is between the browser and the server that can access the requested resource.

It would be nice to have nicely formatted error for HTTP 407 like with the other cases of

def format_error({:proxy, reason}) do
case reason do
:tunnel_timeout ->
"proxy tunnel timeout"
{:unexpected_status, status} ->
"expected tunnel proxy to return a status between 200 and 299, got: #{inspect(status)}"
{:unexpected_trailing_responses, responses} ->
"tunnel proxy returned unexpected trailer responses: #{inspect(responses)}"
http_reason ->
"error when establishing the tunnel proxy connection: " <>
HTTP1.format_error(http_reason)
end
end

@jozuas jozuas changed the title Incorrect proxy HTTP response code range assumption HTTP 407 Error formatting when using proxies Jun 26, 2024
@jozuas jozuas changed the title HTTP 407 Error formatting when using proxies HTTP 407 error formatting when using proxies Jun 26, 2024
@jozuas
Copy link
Author

jozuas commented Jun 26, 2024

The more I'm looking at this ticket, the more unsure I am that it's worth changing anything. Sorry about the noise.

@jozuas
Copy link
Author

jozuas commented Jun 26, 2024

To add to this, I observed that sometimes an unexpected info message after {:proxy, {:unexpected_status, 403}} or {:proxy, {:unexpected_status, 407}} ends up in the process that initiated the request.

Normally, I see something like this:

[warning] {:proxy, {:unexpected_status, 403}}, proxy: <<censored>>
[warning] retry: got exception, will retry in 1000ms, 3 attempts left
[warning] ** (Mint.HTTPError) expected tunnel proxy to return a status between 200 and 299, got: 403
[warning] {:proxy, {:unexpected_status, 407}}, proxy: <<censored>>
[warning] retry: got exception, will retry in 2000ms, 2 attempts left
[warning] ** (Mint.HTTPError) expected tunnel proxy to return a status between 200 and 299, got: 407
[warning] {:proxy, {:unexpected_status, 403}}, proxy: <<censored>>
[error] SomeGenServer: %Mint.HTTPError{reason: {:proxy, {:unexpected_status, 403}}, module: Mint.TunnelProxy}

But sometimese I observe this:

[warning] {:proxy, {:unexpected_status, 403}}, proxy: <<censored>>
[error] %Mint.HTTPError{reason: {:proxy, {:unexpected_status, 403}}, module: Mint.TunnelProxy}
[error] GenServer SomeGenServer terminating
** (FunctionClauseError) no function clause matching in SomeGenServer.handle_info/2
(tp 0.2.0) lib/some_gen_server.ex:153: XXX.handle_info({:tcp, #Port<0.662>, "org/*\">https://xxx.xxx/*</a></p>\n\n<blockquote id=\"error\">\n<p><b>Access Denied.</b></p>\n"}

This unexpected message sometimes happens in the background, but there does not seem to be a way to reliably trigger it for replication.

@ericmj
Copy link
Member

ericmj commented Jun 26, 2024

I think the existing error message is quite clear, do you have a suggestion for how it can be improved?

The FunctionClauseError is not happening in Mint's code, it looks like you have a race condition in your GenServer.

@jozuas
Copy link
Author

jozuas commented Jun 26, 2024

The FunctionClauseError is not happening in Mint's code, it looks like you have a race condition in your GenServer.

@ericmj the GenServer in question uses Req for making requests. Is it normal to get the lower-level messages from Mint in the process that makes requests with Req?

@jozuas
Copy link
Author

jozuas commented Jun 26, 2024

I think the existing error message is quite clear, do you have a suggestion for how it can be improved?

You are completely correct, I realised this here #439 (comment)

@ericmj
Copy link
Member

ericmj commented Jun 26, 2024

the GenServer in question uses Req for making requests. Is it normal to get the lower-level messages from Mint in the process that makes requests with Req?

No, that would be a finch or req issue. They need to keep handling tcp/ssl messages until the controlling process is changed or the connection is closed. The unexpected_status error does not mean the connection is closed.

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

No branches or pull requests

2 participants