Call from go app to postgre db failing
trowlinson
HOBBYOP

2 months ago

I have an App that was working ok. Moved the DB from a simple SQLite DB to a PostgreSQL DB and requests take an age to return. All in the same project and using the internal URL. IPV4 don't seem to connect at all. First request takes over 2 minutes to return. Small DB, with maximum of a couple of dozen rows in the largest table. Error logging at startup with some warmup calls to the DB return following errors. I'm at a loss. I set up a second env with a PostgreSQL and deployed the App with the same result. What is a 'dial error'?

2026/01/14 07:51:30 db warm-up: resolving DB host postgres.railway.internal

2026/01/14 07:51:30 db warm-up: resolved postgres.railway.internal -> [10.240.116.48 fd12:7feb:e1dd:1:9000:44:f270:7430]

2026/01/14 07:51:32 db warm-up: probe tcp 10.240.116.48:5432 failed in 2s: dial tcp 10.240.116.48:5432: i/o timeout

2026/01/14 07:51:34 db warm-up: probe tcp4 10.240.116.48:5432 failed in 2.001s: dial tcp4 10.240.116.48:5432: i/o timeout

2026/01/14 07:51:34 db warm-up: probe tcp [fd12:7feb:e1dd:1:9000:44:f270:7430]:5432 succeeded in 0s

2026/01/14 07:51:34 db warm-up: probe tcp6 [fd12:7feb:e1dd:1:9000:44:f270:7430]:5432 succeeded in 0s

2026/01/14 07:51:34 db warm-up: attempt 4 failed; sleeping 4s before retry

2026/01/14 07:51:38 db warm-up: all 4 attempts failed; last error: failed to connect to user=postgres database=railway:

10.240.116.48:5432 (postgres.railway.internal): dial error: timeout: context deadline exceeded

[fd12:7feb:e1dd:1:9000:44:f270:7430]:5432 (postgres.railway.internal): dial error: timeout: context deadline exceeded

10.240.116.48:5432 (postgres.railway.internal): dial error: timeout: context deadline exceeded

[fd12:7feb:e1dd:1:9000:44:f270:7430]:5432 (postgres.railway.internal): dial error: timeout: context deadline exceeded

Solved$10 Bounty

7 Replies

Railway
BOT

2 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


ilyassbreth
FREE

2 months ago

what's definitely happening: ipv4 connections timing out (10.240.116.48:5432 - 2+ seconds) , and ipv6 connections working instantly (fd12:... - 0 seconds) , postgres itself is running fine

so if your environment was created before oct 16 2025 , it's a "legacy" ipv6-only environment, your go app tries ipv4 first which times out. proven fix from railway docs:

go

config, err := pgxpool.ParseConfig(os.Getenv("DATABASE_URL"))
config.ConnConfig.DialFunc = func(ctx context.Context, network, addr string) (net.Conn, error) {
    return (&net.Dialer{}).DialContext(ctx, "tcp6", addr)
}
pool, err := pgxpool.NewWithConfig(context.Background(), config)

ilyassbreth
FREE

2 months ago

a guaranteed workaround is to use DATABASE_PUBLIC_URL temporarily to confirm postgres works, then you know it's the private network issue

check when your railway environment was created. if before oct 16 2025, option 1 will fix it. the tcp6 forces ipv6-only connections which your logs show work perfectly


ilyassbreth
FREE

2 months ago

i hope this help you, let me know the result

ilyass


trowlinson
HOBBYOP

2 months ago

Thank you ilyass for your quick replies on this. It is great to see a community that works!

I tried putting your code fix to force ipv6 connection (I had tried this before but I was up for trying anything) and it worked! I checked the logs and could see all connections, both ipv6 and ipv4, were working again. Odd, I thought, so I removed the new code forcing the ipv6 connection and it still works.

I may be wrong, but this seems to have been an environment issue. I'm not sure if anyone else was affected but nothing changed in my project other than the passage of time, and it all now works again.

Odd.

Just a note that the environment was created in the last few days so the ipv6 issue shouldn't have affected it. Shouldn't have...


ilyassbreth
FREE

2 months ago

glad it's working now , since your environment was created in the last few days , it should have dual-stack ipv4/ipv6 support by default according to railway's docs. so the tcp6 fix shouldn't have been necessary for your setup.

whatever caused the temporary connection issues seems to have resolved. keep monitoring it to make sure it stays stable.


ilyassbreth
FREE

2 months ago

happy it works for you slightly_smiling_face emoji


Status changed to Solved brody about 2 months ago


Loading...