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

tl;dr Tesla.Middleware.Timeout, timeout: 15000 should work but due to unfortunate complexities you must also set recv_timeout.

See this issue for more:

IIRC I ended up ditching the Timeout middleware completely for the reason you mentioned, also because that same middleware doesn’t work with Tesla.Mock (I think that was the one?).