iampeter

iampeter

Connection timeout with Ecto / Postgrex and Neon

Hi, I am getting a connection timout with Ecto when connecting to Neon. Neon suspends their Postgresql instances and the timeout happens when the instance is being unsuspended. According to Neon logs, the instance wakes up in around 200ms, but Ecto gives me a timeout after 15s.

Here are my Ecto settings:

  config :myapp, Myapp.Repo,
    url: database_url,
    pool_size: String.to_integer(System.get_env("POOL_SIZE") || "10"),
    socket_options: maybe_ipv6,
    queue_target: System.get_env("DATABASE_QUEUE_TARGET") || 5_000,
    queue_interval: System.get_env("DATABASE_QUEUE_INTERVAL") || 10_000,
    ssl: [
      verify: :verify_none
    ]

And here is the error:

2024-06-17T23:45:13Z app[148e259ec31908] syd [info]23:45:13.752 request_id=F9nvXJYStmadsPgAAAXh [info] GET /apply
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.416 [error] Postgrex.Protocol (#PID<0.2225.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.417 [error] Postgrex.Protocol (#PID<0.2222.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.417 [error] Postgrex.Protocol (#PID<0.2221.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2226.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2227.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2228.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2229.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2230.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2231.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:23Z app[148e259ec31908] syd [info]23:45:23.418 [error] Postgrex.Protocol (#PID<0.2232.0>) failed to connect: ** (DBConnection.ConnectionError) tcp connect (my-instance-url.ap-southeast-2.aws.neon.tech:5432): timeout
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]23:45:30.065 [error] Postgrex.Protocol (#PID<0.2230.0>) disconnected: ** (DBConnection.ConnectionError) client #PID<0.2560.0> timed out because it queued and checked out the connection for longer than 15000ms
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]#PID<0.2560.0> was at location:
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (stdlib 6.0) gen.erl:241: :gen.do_call/4
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (stdlib 6.0) gen_statem.erl:2633: :gen_statem.call/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ssl 11.2) tls_sender.erl:666: :tls_sender.call/2
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (postgrex 0.18.0) lib/postgrex/protocol.ex:3374: Postgrex.Protocol.do_send/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (postgrex 0.18.0) lib/postgrex/protocol.ex:1539: Postgrex.Protocol.close_parse_describe_flush/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (postgrex 0.18.0) lib/postgrex/protocol.ex:370: Postgrex.Protocol.handle_prepare/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (db_connection 2.6.0) lib/db_connection/holder.ex:354: DBConnection.Holder.holder_apply/4
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (db_connection 2.6.0) lib/db_connection.ex:1497: DBConnection.prepare/4
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]23:45:30.071 request_id=F9nvXJYStmadsPgAAAXh [info] Sent 500 in 16318ms
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]23:45:30.072 request_id=F9nvXJYStmadsPgAAAXh [error] ** (DBConnection.ConnectionError) ssl recv (idle): closed (the connection was closed by the pool, possibly due to a timeout or because the pool has been terminated)
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:1054: Ecto.Adapters.SQL.raise_sql_call_error/1
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ecto_sql 3.11.2) lib/ecto/adapters/sql.ex:952: Ecto.Adapters.SQL.execute/6
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ecto 3.11.2) lib/ecto/repo/queryable.ex:232: Ecto.Repo.Queryable.execute/4
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ecto 3.11.2) lib/ecto/repo/queryable.ex:19: Ecto.Repo.Queryable.all/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (ecto 3.11.2) lib/ecto/repo/queryable.ex:154: Ecto.Repo.Queryable.one/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (myapp 0.1.0) lib/myapp/marks.ex:47: Myapp.Marks.get_or_new_application/1
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (myapp 0.1.0) lib/myapp_web/live/application_live/index.ex:12: MyappWeb.ApplicationLive.Index.mount/3
2024-06-17T23:45:30Z app[148e259ec31908] syd [info]    (phoenix_live_view 0.20.14) lib/phoenix_live_view/utils.ex:354: anonymous fn/6 in Phoenix.LiveView.Utils.maybe_call_live_view_mount!/5

Outside of the unsuspention period, connections work fine.
I am not sure what DBConnection params I should be looking to tweak.
Any help appreciated.

Thanks,
PG

Marked As Solved

iampeter

iampeter

Apparently, this might have been a networking issue, I am not experiencing it anymore.

Where Next?

Popular in Questions Top

pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
kostonstyle
Hi all I want to have a unix time, from the current time plus 1 hour. DateTime.now + 1 hour How to get it in elixir? Thanks
New
chewm
Hi guys, nice to meet you to the whole forum, I’m new here, I’m trying to configure visual studio code for elixir, right now the intellis...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
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
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 45766 226
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
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
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New

We're in Beta

About us Mission Statement