Cannot connect to a Digital Ocean hosted database after deploying

Hi! I’ve just deployed a NodeJS application using Fly.io. However my Digital Ocean database requires that I add the IP of the app as a “trusted source” in order to connect to it properly. I tried adding the IPv4 address that’s displayed in my dashboard with no luck. Is there a specific IP I should be adding instead?

This is similar to this question, except they disabled trusted sources and I don’t set socket_options :thinking:

For reference, this is from the fly error logs:

UnhandledPromiseRejectionWarning: Error: {"is_panic":false,"message":"Can't reach database server at `xxxx-3203921-0.b.db.ondigitalocean.com`:`25060`\n\nPlease make sure your database server is running at `xxxx-3203921-0.b.db.ondigitalocean.com`:`25060`.","meta":{"database_host":"xxxx-3203921-0.b.db.ondigitalocean.com","database_port":25060},"error_code":"P1001"}
2021-10-22T02:42:27.185 app[dc16e717] lax [info] (Use `node --trace-warnings ...` to show where the warning was created)

Any insight would be really helpful, thank you!

EDIT: Ok I bit the bullet and removed the requirement to connect from a trusted IP source…and it connected just fine. Clearly it’s an IP issue. So my question now is, what IP should my database be allowing connections from if not the IPv4 that’s listed in my Fly dashboard :exploding_head:

# fly.toml file generated for graphql-staging on 2021-10-21T18:39:37-07:00

app = "graphql-staging"

kill_signal = "SIGINT"
kill_timeout = 5
processes = []

[env]

[experimental]
  allowed_public_ports = []
  auto_rollback = true

[[services]]
  http_checks = []
  internal_port = 4001
  processes = ["app"]
  protocol = "tcp"
  script_checks = []

  [services.concurrency]
    hard_limit = 25
    soft_limit = 20
    type = "connections"

  [[services.ports]]
    handlers = ["http"]
    port = 80

  [[services.ports]]
    handlers = ["tls", "http"]
    port = 443

  [[services.tcp_checks]]
    grace_period = "1s"
    interval = "15s"
    restart_limit = 0
    timeout = "2s"
1 Like

Yes, you’re right it’s the IP that’s the issue.

Unfortunately the IP that Fly shows you is the one for incoming requests to the app. They don’t reveal the outgoing IP. Which is what you need when using an external database that needs an IP.

Fly can provide an IP range for a particular region but those IPs are subject to change. So that is half-way there but not ideal. I’m not aware of a solution to getting a fixed IP.

See e.g

Did you manage to find a solution for this? I’m running through this right now.

Yea, had to remove the requirement from a trusted IP source.