Database transaction longer than a minute fails with "Mariaex.Protocol disconnected" error

Hi,

My team is developing an application that must integrate with another 3rd party system and I am making a simulator for the 3rd party system in Phoenix.

One of the integration use cases that our application must handle is when we make API requests from our app to which the 3rd party system is responding slow (in a couple of minutes).

While processing a request of this type, the Phoenix simulator I am writing is making a large DB transaction (it inserts many rows in one MariaDB table). The problem that I am facing is that after exactly one minute, the transaction fails with the following error message:

[error] Mariaex.Protocol (#PID<0.nnn.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.mmm.0> exited

In the test environment, I could solve the problem (i.e. make a ExUnit test that calls a request which makes a DB transaction longer than one minute) by adding the @tag timeout: 120_000 to the test case and by passing ownership_timeout: 120_000 option to the Ecto.Adapters.SQL.Sandbox.checkout function call.

However in the dev / prod environment I could not find a way to increase the timeout of the transaction, even if I set timeout: 120_000 option to the Repo configuration. It seems that in the test env the DB connection pool implementation is different than the “normal” connection pool. Can you please direct me to what am I missing?

Thanks.

P.S. I am pretty new to Phoenix and Elixir, but I love it.

1 Like

If the client exited, then this sounds like the actual HTTP request process is the thing timing out, not the ecto query. I would make sure that Phoenix / Plug / Cowboy doesn’t havesome kind of 60 second timeout for requests, and that your client is also OK with a long lived HTTP request.

2 Likes

:dart:

Cowboy does, from https://github.com/ninenines/cowboy/blob/master/doc/src/manual/cowboy_http.asciidoc

idle_timeout (60000)
Time in ms with no data received before Cowboy closes the connection.

For more: https://github.com/ninenines/cowboy/search?q=60000&unscoped_q=60000

3 Likes

Beautiful!

Indeed, the issue was solved by adding the following endpoint configuration:

config :long_req, LongReqWeb.Endpoint,
  [...]
  http: [protocol_options: [idle_timeout: 120_000]]

Thank you both!
Dan

5 Likes