Strange behaviour Mojito http client

I noticed a strange behaviour when using Mojito http client in production, though the upstream node is responding to the request within the specified time, Mojito is reporting of a timeout. This does not happen to all request. Could it be an issue with my code, kindly find below.

  timeout =  String.to_integer( Application.get_env(:bonus, :hss_timeout))
  connect_timeout = String.to_integer(Application.get_env(:bonus, :connect_timeout))

  {_ignore, response} = 
  Application.get_env(:bonus, :sim_check_hss)
  |>[{"Content-Type", "text/xml; charset=UTF-8"}, {"Content-Length", "#{String.length(request)}"}], request, timeout: timeout, pool: false, transport_opts: [timeout: connect_timeout])"HSS response [#{msisdn}:" <> inspect(Map.get(response, :body) || Map.get(response, :reason)) <> "]")


Thank you

Have you inspected the exact values and types of timeout and connect_timeout?

I’m still looking into the issue, educate me on this, when an http client times out, does the server still send the response?

Definitely not. “Timeout” means: “I stopped trying to reach the server because it did not respond anything within the timeout period”.

I did a basic test, seems that the server sends the response even if the client timeout. I sleep in a script for 10s, set the timeout parameter to 5s in the client, though the client timeout without receiving any response, the tcpdump shows that the response was actually sent from the server.

@dimitarvp, is there anything I’m missing in my simulation. I did the test using php and libcurl while I took a tcp dump on the client.

The http client timeout works just like when you are waiting for someone to arrive at 9pm and after 9:05pm you gave up on waiting and you go away with your life, but then the other person arrives to the meeting place at 9:06pm, but you are not their anymore :wink:

1 Like

Thanks a bunch for the explanation, all doubts cleared. I was thinking TCP will close the connection once the http client timeout. Awesome.