madasebrof

madasebrof

Super weird http issue

Wow, this is an odd one.

I’m making an http request (post) to a server.

  1. Work fine from curl
  2. Works fine from iex
  3. Bombs out when I run from within app!

I have literally never had this happen before, when the EXACT same function behaves differently live vs. iex.

Just wondering if anyone has insight into some magic that might be going on behind the scenes that could be causing this! (This is a phoenix app, but doesn’t seem phoenix-related…)

I even added a checksum function to make sure the data being sent was identical & there wasn’t some odd file-write delay causing the issue.

Example - Success from iex (note–iex is actually connected to the running app!):

iex(91be5e1d30ff@172.21.0.3)5> Polo.Ib.Connect.post(body, "/create") 
13:24:11.570 [info]  Ib.Connect.post endpoint: [ https://qa.xyz.com/ws/eca/create ]
13:24:11.573 [warn]  
Mojito.request(
  method: :post,
  url: https://qa.xyz.com/ws/eca/create,
  headers: [{"Content-Type", "application/json"}, {"User-Agent", "Elixir"}, {"Accept", "*/*"}],
  body: data -> checksum = 904033a8a73bdea778edf96317957f40704686cd,
  opts: [timeout: 180_000, transport_opts: [verify: :verify_none]]
)

{:ok,
 %{
   "batchId" => 305738,
   "fileData" => %{
     "data" => "hQ ... eFBJXdc/cKHQ==",
     "name" => "sgimFA_20200211-082414031_965716.xml"
   },
   "isProcessed" => true,
   "timestamp" => "2020-02-11 08:24:15"
 }}

works great!

From with the app, when running programmatically, I get

[info] Ib.Connect.post endpoint: [ https://qa.xyz.com/ws/eca/create ]
[warn] 

Mojito.request(
  method: :post,
  url: https://qa.xyz.com/ws/eca/create,
  headers: [{"Content-Type", "application/json"}, {"User-Agent", "Elixir"}, {"Accept", "*/*"}],
  body: data -> checksum = 904033a8a73bdea778edf96317957f40704686cd,
  opts: [timeout: 180_000, transport_opts: [verify: :verify_none]]
)

[error] %Mojito.Response{body: "<!DOCTYPE html>\n<html>
\n<head>\n<title>Account Management Unavailable | ... \" content=\"500 Error\">\n<<> ..., 
complete: true, 
headers: [{"date", "Tue, 11 Feb 2020 13:21:47 GMT"}, 
{"server", "Apache"}, 
{"vary", "\\\"Origin\\\""}, 
{"content-security-policy", "frame-ancestors 'self'  ... .com;"}, 
{"content-length", "5879"}, 
{"connection", "close"}, 
{"content-type", "text/html; charset=UTF-8"}], 
status_code: 500}

Note that the checksum of the data is identical! The headers are identical! It’s literally the exact same function with identical arguments.

I am just totally at a loss as to what could be different.

Any thoughts are appreciated!

ps Was using HTTPPoision, then switched to Mojito/Mint to see if that would fix, but same issue.

Most Liked

voltone

voltone

Decrypting TLS would be possible in two scenarios:

  1. You have access to the server’s private key and you constrain the negotiated cipher suites to ensure the key exchange does not use (EC)DHE, or
  2. You write the master secret for the session you want to decode to a file

This last option can work both on the server side (if you control the server) or on the client side (using Erlang’s :ssl.connection_information(socket, [:client_random, :master_secret]).

But there is an easier way: use Erlang’s tracing functionality, e.g. using :dbg or some higher level abstraction such as recon:

iex(1)> :dbg.tracer()                                                            
{:ok, #PID<0.258.0>}
iex(2)> :dbg.p(:all, :call)                                                      
{:ok, [{:matched, :nonode@nohost, 119}]}
iex(3)> :dbg.tp({Mint.Core.Transport.SSL, :send, :_}, :cx)                       
{:ok, [{:matched, :nonode@nohost, 1}, {:saved, :cx}]}
iex(4)> {:ok, response} = Mojito.request(method: :get, url: "https://github.com")
(<0.269.0>) call 'Elixir.Mint.Core.Transport.SSL':send({sslsocket,{gen_tcp,#Port<0.6>,tls_connection,undefined},
           [<0.303.0>,<0.302.0>]},[[<<"GET">>,32,<<"/">>,<<" HTTP/1.1\r\n">>],
 [[[<<>>,<<"content-length">>,<<": ">>,<<"0">>,<<"\r\n">>],
   <<"host">>,<<": ">>,<<"github.com">>,<<"\r\n">>],
  <<"user-agent">>,<<": ">>,<<"mint/1.0.0">>,<<"\r\n">>],
 <<"\r\n">>,<<>>]) ({'Elixir.Mint.HTTP1',request,5})
(<0.269.0>) returned from 'Elixir.Mint.Core.Transport.SSL':send/2 -> ok
{:ok,
 %Mojito.Response{...}

It takes a second to spot the actual request data in the output and perhaps reformat it, but it is much easier than setting up TLS decoding :slight_smile:

madasebrof

madasebrof

At the end of the day, I think it’s just a super flaky endpoint, and it was more coincidence that some requests were working and other were not!

I just tried 4 request in a row–first 3 bombed, last one went through.

Again, thanks for all ideas!

Rock on,

Where Next?

Popular in Questions Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
Tee
can someone please explain to me how Enum.reduce works with maps
New
Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&amp;query=perfume&amp;page=2, I would like to get: ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
nsuchy
Hi. I’ve noticed that Windows Powershell has it’s own IEX command and you cannot access Elixir’s IEX due to the conflict. This isn’t a cr...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
yawaramin
In the Dialyzer docs ( dialyzer — OTP 29.0.2 (dialyzer 6.0.1) ), there is a way to turn off a specific warning for a function: -dialyzer...
New
vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New

Other popular topics Top

jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36352 110
New
boundedvariable
I am going through the kafka architecture. All the features what the kafka is providing are already in Erlang. I would like hear your opi...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" =&gt; #BSON.ObjectId&lt;58eb1a7a9ad169198c3dXXXX&gt;, "email" =&gt; ...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New

We're in Beta

About us Mission Statement