`tcp recv (idle): closed` reconnecting after a while

I have an Elixir app on Fly connected to Fly Postgres.
Every time I reconnect to the app in a while, it errors with

tcp recv (idle): closed

The app works normally if I make another request.

The app uses Bandit 1.5 and Postgrex 0.19 without Phoenix or Ecto. The error is probably from DBConnection.

DBConnection.ConnectionError tcp recv (idle): closed

Searching for similar cases and fiddling configurations didn’t help.
What would be causing this error?
What can I do?

Related configurations

# runtime.exs
db = System.fetch_env!("DATABASE_URL") |> URI.parse()
[db_user, db_pass] = String.split(db.userinfo, ":")

config :postgrex,
  username: db_user,
  password: db_pass,
  hostname: db.host,
  database: db.path |> Path.basename(),
  pool_size: 10,
  timeout: 60_000,
  socket_options: [:inet6]
# fly.toml
app = "pillars"
primary_region = "lhr"
kill_signal = "SIGTERM"

[build]
dockerfile = "../../Dockerfile"
ignorefile = "../../.dockerignore"

[build.args]
APP = "pillars"

[env]
PORT = "8080"
ERL_AFLAGS = "-proto_dist inet6_tcp"

[http_service]
internal_port = 8080
force_https = true
auto_stop_machines = "suspend"
auto_start_machines = true

[[vm]]
size = "shared-cpu-1x"

The Postgres fly.toml is pretty much the default.
All machines are shared-cpu-1x@256MB

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.