Repository navigation
PostgreSQL connection timeout when registering with Better Auth and Prisma #30651
Replies: 3 comments 1 reply
|
The shape of the error tells you most of it. When adapter-pg recognises a socket error it maps it to a Prisma code (ETIMEDOUT becomes P1008, ECONNREFUSED/ENOTFOUND become P1001) and puts orm/packages/adapter-pg/src/errors.ts Lines 249 to 263 in e92bc46 That's what Node throws when the hostname resolves to more than one address (IPv6 + IPv4, or several A records) and every connect attempt fails: an AggregateError carrying the attempts' code. So the TCP connection to Postgres was never established. It isn't SSL (TLS only starts after TCP connects, and TLS failures map to a different error) and it isn't auth. The pg-connection-string warning only says sslmode=require/prefer are now treated as verify-full. Unrelated. Check reachability outside Prisma, with the same URL and from the same shell that runs // check.mjs
import dns from 'node:dns/promises'
import net from 'node:net'
const u = new URL(process.env.DATABASE_URL)
console.log(await dns.lookup(u.hostname, { all: true }))
const s = net.connect({ host: u.hostname, port: Number(u.port || 5432), timeout: 5000 })
s.on('connect', () => { console.log('tcp ok'); s.end() })
s.on('timeout', () => { console.log('tcp timeout'); s.destroy() })
s.on('error', (e) => console.log(e.name, e.code, e.errors?.map((x) => `${x.address} ${x.code}`)))
If that times out too, it's the network and not Prisma. Usual suspects: Postgres not listening on that interface, a firewall or IP allowlist on a hosted DB, or, if this is WSL2, |
|
Hi @kgeminicdev , I ran the check.mjs script as you suggested, and the result confirms the network issue. Here’s the output: As you pointed out, this confirms that the TCP connection to Postgres is never established. The IPv4 addresses time out (ETIMEDOUT) and IPv6 is unreachable (ENETUNREACH). This looks like a Security Group issue on AWS (since the DB is hosted there). I’ll check if the inbound rule on port 5432 allows traffic from my server’s public IP. Thanks for the detailed diagnosis ! |
|
Since your check already shows the TCP connection is never established (every resolved IP times out, IPv6 is unreachable), you can rule out most of the stack: it's not Better Auth, not Prisma, and not SSL. The SSL warning is unrelated — For a local dev machine connecting to a database on AWS, the suspects in order:
One test separates 1+2 from 3 in a minute: connect your machine to a phone hotspot and run the same check script. If it connects from the hotspot, the problem is your normal network or its public IP (suspects 1/3). If it still times out everywhere, it's the AWS side (suspect 2, or an SG/NACL rule). And to take Prisma completely out of the equation while testing, try from the same machine: nc -vz <your-db-host> 5432
# or
psql "$DATABASE_URL" -c 'select 1'If those time out too, no client-side change will fix it — the fix lives in the network path. My money is on #1 or #3, given DNS resolves fine but every single IP swallows the packets. |
Uh oh!
There was an error while loading. Please reload this page.
Hello,
I'm encountering an error when trying to sign up in my Next.js app using Better Auth and Prisma 7. The
/signuppage displays correctly (GET /signupreturns a200status code), but the sign-up request fails :The error occurs when Better Auth uses Prisma to execute
findFirst()on theUsermodel. The query takes about 18 seconds before failing. I also saw a warning regarding the SSL modes inpg-connection-string, but I’m not sure if it’s related to this error.How can I determine whether this
timeoutis due toPostgreSQLavailability, the connection configuration, the network, orSSL, and what checks do you recommend to resolve it?All reactions