Tesla.Middleware.Timeout doesn't set my timeout

I just created a local endpoint to take seconds whatever I set like this

http://localhost:4000/dev/timeout?seconds=60 This will just sleep for 60 seconds.

To test in iex console

client = Tesla.client([{Tesla.Middleware.Timeout, timeout: 15000}])

%Tesla.Client{
  fun: nil,
  pre: [{Tesla.Middleware.Timeout, :call, [[timeout: 15000]]}],
  post: [],
  adapter: nil
}

Tesla.get(client, "http://localhost:4000/dev/timeout?seconds=60")

After 10 seconds it return timeout errors
{:error, :timeout}

I expected it takes 15seconds. but it just takes 10 seconds to timeout.

But if set this in config.exs. It takes 15 seconds to the timeout error

config :tesla, adapter: {Tesla.Adapter.Hackney, [recv_timeout: 15_000]}

What am I missing?

1 Like