-
Notifications
You must be signed in to change notification settings - Fork 428
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
{:error, :closed} response when using proxy #621
Comments
Interesting that using Mint I got the same connection error with and without proxy. 🤔 # Without proxy
Mint.HTTP.connect(:https, "apps.correios.com.br", 443)
{:error, %Mint.TransportError{reason: :closed}}
# With proxy
Mint.HTTP.connect(:https, "apps.correios.com.br", 443, proxy: {:http, "localhost", 8888, []})
%Mint.TransportError{reason: %Mint.TransportError{reason: :closed}} Tinyproxy logs:
I have opened an issue in Mint too: elixir-mint/mint#255 |
Using httpc happens a similar connection error with and without proxy. url = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente'
headers = [{'Accept', 'text/xmll'}]
content_type = 'text/xml; charset=utf-8'
body =
String.to_charlist("""
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header />
<soapenv:Body>
<cli:consultaCEP>
<cep>13212-070</cep>
</cli:consultaCEP>
</soapenv:Body>
</soapenv:Envelope>
""")
:inets.start()
:ok
:ssl.start()
:ok
# Without proxy
:httpc.request(:post, {url, headers, content_type, body}, [], [])
{:error,
{:failed_connect,
[{:to_address, {'apps.correios.com.br', 443}}, {:inet, [:inet], :closed}]}}
# With proxy
:httpc.set_options([{:proxy, {{'localhost', 8888}, []}}])
:ok
:httpc.request(:post, {url, headers, content_type, body}, [], [])
{:error,
{:failed_connect,
[
{:to_address, {'apps.correios.com.br', 443}},
{:tls, [server_name_indication: 'apps.correios.com.br'], :closed}
]}} Tinyproxy logs:
I could make a successful request to the host |
Just for a reference using ibrowse, without proxy returns url = 'https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente'
headers = [
{'Accept', 'text/xmll'},
{'Content-Type', 'text/xml; charset=utf-8'}
]
body =
String.to_charlist("""
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header />
<soapenv:Body>
<cli:consultaCEP>
<cep>13212-070</cep>
</cli:consultaCEP>
</soapenv:Body>
</soapenv:Envelope>
""")
# Without proxy
:ibrowse.send_req(url, headers, :post, [body])
{:error, {:conn_failed, {:error, :closed}}}
# With proxy
:ibrowse.send_req(url, headers, :post, [body], [proxy_host: 'localhost', proxy_port: 8888])
{:error, :retry_later} Tinyproxy logs:
|
Another reference using # Timeout
{:ok, conn} = :gun.open('apps.correios.com.br', 443)
:gun.await_up(conn)
{:error, :timeout}
# Setting a long connection timeout
{:ok, conn} = :gun.open('apps.correios.com.br', 443)
:gun.await_up(conn, 30000)
{:error, {:shutdown, :closed}} I have opened an issue in Gun too: ninenines/gun#228 |
I have tested HTTP connection/request to the host
So, what is "the magic" |
I could make it work with proxy using the cipher AES256-SHA256 and TLS version 1.2. url = "https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente"
headers = [{"Content-Type", "text/xml; charset=utf-8"}]
body = """
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header />
<soapenv:Body>
<cli:consultaCEP>
<cep>13212-070</cep>
</cli:consultaCEP>
</soapenv:Body>
</soapenv:Envelope>
"""
options = [
proxy: {"127.0.0.1", 8888},
ssl_options: [ciphers: ['AES256-SHA256'], versions: [:"tlsv1.2"]],
with_body: true
]
:hackney.post(url, headers, body, options)
{:ok, 200,
[
{"Date", "Mon, 04 May 2020 22:08:55 GMT"},
{"Server", "Apache/2.4.10 (Debian)"},
{"X-OPNET-Transaction-Trace", "a2_17dcfce9-5957-4b97-a769-481988faf643"},
{"Content-Type", "text/xml;charset=UTF-8"},
{"Content-Length", "422"},
{"Vary", "Accept-Encoding,User-Agent"},
{"Set-Cookie",
"_op_aixPageId=a2_17dcfce9-5957-4b97-a769-481988faf643; Path=/"},
{"Set-Cookie",
"app-%3FINTERNO%3Fpool_proxy_app_sigep_443=POCCAIAK; Expires=Mon, 04-May-2020 22:28:57 GMT; Path=/"},
{"Set-Cookie",
"sto-id-%3FEXTERNO_2%3Fpool_Proxy_reverso_Apps_443=BIABKIMA; Expires=Mon, 04-May-2020 22:28:57 GMT; Path=/"}
],
"<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body><ns2:consultaCEPResponse xmlns:ns2=\"http://cliente.bean.master.sigep.bsb.correios.com.br/\"><return><bairro>Parque Residencial Eloy Chaves</bairro><cep>13212070</cep><cidade>Jundiaí</cidade><complemento2></complemento2><end>Avenida Benedicto Castilho de Andrade</end><uf>SP</uf></return></ns2:consultaCEPResponse></soap:Body></soap:Envelope>"} The original solution is from ninenines/gun#228. The question is: why when using a proxy the behaviour is different from the request not using proxy? 🙂 |
did you try with the latest master? |
@prodis bump. |
With hackney 1.16.0 I am receiving url = "https://apps.correios.com.br/SigepMasterJPA/AtendeClienteService/AtendeCliente"
headers = [{"Content-Type", "text/xml; charset=utf-8"}]
body = """
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cli="http://cliente.bean.master.sigep.bsb.correios.com.br/">
<soapenv:Header />
<soapenv:Body>
<cli:consultaCEP>
<cep>13212-070</cep>
</cli:consultaCEP>
</soapenv:Body>
</soapenv:Envelope>
"""
:hackney.post(url, headers, body, with_body: true)
{:error, :closed}
:hackney.post(url, headers, body, with_body: true, proxy: {"127.0.0.1", 8888})
{:error, :closed} It only works using the option |
FWIW, I am using the following ssl options to mitigate some of these closed connections when using a proxy where ssl_options = [
versions: [:"#{message.protocol}"],
server_name_indication: '#{message.host_name}',
reuse_sessions: false,
verify: :verify_none,
depth: 3,
ciphers: :ssl.cipher_suites(:all, message.protocol |> String.to_atom, :openssl) ++ :ssl.cipher_suites(:all, message.protocol |> String.to_atom, :rfc)
] |
|
It's been a few years; is this still an issue? |
I am using
hackney
via HTTPoison and in a request for a specific host I am getting{:error, :closed}
when making the request through a proxy. In the beginning my assumption was some problem with the proxy, but using different proxies I got the same error. And testing different proxies requesting to the different hosts worked fine.I could not identify what this specific host that I am requesting has different that
hackney
closes the connection. Doing the same request withcurl
using a proxy works fine.The following examples are using Tinyproxy.
hackney without proxy works fine
hackney with proxy returns closed error
Tinyproxy logs:
curl with proxy works fine
Tinyproxy logs:
My system info
More tests
Curious about running
hackney
on Linux with different OTP versions, I created some tests to run in Travis CI making the requests to the URL with the problem and to another URL that works fine using or not proxy.The integration tests are here:
The results in Travis CI are here: https://travis-ci.org/github/prodis/correios-cep-elixir/builds/681723934
The
{:error, :closed}
is the same running on Travis, except for OTP 20.0 that withhackney
using proxy works fine for the URL with the problem, but it fails for the another URL (jsonplaceholder.typicode.com) returning 404 for the request. 🙃Take a look in this result using Elixir 1.9 and OTP Release 20.0: https://travis-ci.org/github/prodis/correios-cep-elixir/jobs/681723939
Any idea what is going on? 🙂
Let me know if you need more information.
The text was updated successfully, but these errors were encountered: