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

This thread may be helpful:

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