N
Neon2y ago
ratty-blush

Error connecting neon.tech db to the node.js application

When I try to connect to the database on the neon tech , I am always getting an error stating that AggregateError ETIMEDOUT ENETUNREACH Code and Error is mentioned
No description
No description
42 Replies
inland-turquoise
inland-turquoise2y ago
hmm, this seems to imply you cannot establish a TCP connection to our load balancer. Odd. Can you try run
curl -X OPTIONS "https://api.us-east-1.aws.neon.tech/sql" -v
curl -X OPTIONS "https://api.us-east-1.aws.neon.tech/sql" -v
and see if that works
ratty-blush
ratty-blushOP2y ago
I am getting this error : "query is not supported" @Conrad Ludgate
inland-turquoise
inland-turquoise2y ago
Ok that's fine. You did at least connect to our backend. Is the node application still having issues?
ratty-blush
ratty-blushOP2y ago
Yes, the same error that I shared earlier still exists Two codes are commonly mentioned: ENETUNREACH ETIMEDOUT
fair-rose
fair-rose2y ago
Can you share the code you're using to connect? Edit: I didn't see the second screenshot. Ignore. Can you connect using other tools, such as the psql CLI? And also try changing your DNS server to 1.1.1.1 or 8.8.8.8, just to see. We had a user with odd DNS issues once before
fascinating-indigo
fascinating-indigo2y ago
Hello! also getting those same errors persistently: even with the code from the neon docs on the official website
fair-rose
fair-rose2y ago
Can you try the suggestions I posted above and let me know your results? Where are you located? I wonder if this is related to your network
fascinating-indigo
fascinating-indigo2y ago
no connection at all'
No description
No description
fascinating-indigo
fascinating-indigo2y ago
trying to debug with a friend from 2 different countries andstill nothing... same errors persist
fair-rose
fair-rose2y ago
This doesn’t answer my question, unfortunately. We’ll need to go step by step. 1. Does psql work? 2. Does changing DNS work? 3. Can you share you database host name? (Don’t post the user/pass)
fascinating-indigo
fascinating-indigo2y ago
psql works strangely enough
fair-rose
fair-rose2y ago
🤯 oh wow! So this might be something funky with either Node.js or a combination of the Node.js version and Postgres driver. Can you share what you get from node -v? And which version of the Postgres package you’re using cat node_modules/postgres/package.json | grep version?
fascinating-indigo
fascinating-indigo2y ago
database hostname: ep-empty-limit-a5p0ulnq.us-east-2.aws.neon.tech node -v (my-friend): 20.5.1 node -v (mine): 21.6.1 postgres version(both): 3.4.3 other database hostname: ep-super-field-a5ze6tni.us-east-2.aws.neon.tech
fascinating-indigo
fascinating-indigo2y ago
my application which was working previously with Prisma fails as well:
No description
fair-rose
fair-rose2y ago
When I try to connect to ep-empty-limit-a5p0ulnq.us-east-2.aws.neon.tech I receive an authentication error. No issues with connectivity to the endpoint itself. Can you try 1. Changing DNS (I know, sounds pointless but worked for someone in the past) 2. Connecting from a totally different host, e.g DigitalOcean 3. Removing pg-pool? I see in the previous screenshot pool is used. I used just the following code to confirm connectivity:
const postgres = require('postgres');

require('dotenv').config();

let { PGHOST, PGDATABASE, PGUSER, PGPASSWORD } = process.env;

const sql = postgres({
host: PGHOST,
database: PGDATABASE,
username: PGUSER,
password: PGPASSWORD,
port: 5432,
ssl: 'require'
});

async function getPgVersion() {
const result = await sql`select version()`;
console.log(result[0]);
}

getPgVersion();
const postgres = require('postgres');

require('dotenv').config();

let { PGHOST, PGDATABASE, PGUSER, PGPASSWORD } = process.env;

const sql = postgres({
host: PGHOST,
database: PGDATABASE,
username: PGUSER,
password: PGPASSWORD,
port: 5432,
ssl: 'require'
});

async function getPgVersion() {
const result = await sql`select version()`;
console.log(result[0]);
}

getPgVersion();
I used the following versions:
[10:45:30] evanshortiss@neon-mbp /Users/evanshortiss/workspaces/neon-nodejs-example
> node -v
v21.5.0
[10:47:54] evanshortiss@neon-mbp /Users/evanshortiss/workspaces/neon-nodejs-example
> cat node_modules/postgres/package.json | grep version
"version": "3.4.3",
[10:45:30] evanshortiss@neon-mbp /Users/evanshortiss/workspaces/neon-nodejs-example
> node -v
v21.5.0
[10:47:54] evanshortiss@neon-mbp /Users/evanshortiss/workspaces/neon-nodejs-example
> cat node_modules/postgres/package.json | grep version
"version": "3.4.3",
fascinating-indigo
fascinating-indigo2y ago
no luck with the pg-pool fix, both of us are on different dns servers, google, and cloudflare and still getting the same errors
fair-rose
fair-rose2y ago
Can you try a host like DigitalOcean. Since I can connect, it suggests the error is with your network(s)/app(s) unfortunately.
inland-turquoise
inland-turquoise2y ago
It's very suspicious that psql would work but nodejs wouldnt
fair-rose
fair-rose2y ago
Great point too. Could this be some bizarro TLS issue?
fascinating-indigo
fascinating-indigo2y ago
tested on an aws server in us-east region and timed out as well
No description
fascinating-indigo
fascinating-indigo2y ago
check your dm
inland-turquoise
inland-turquoise2y ago
Port 5000?
fascinating-indigo
fascinating-indigo2y ago
yeah... testing on a different port.. gets same error
inland-turquoise
inland-turquoise2y ago
GitHub
Receiving Can't reach database server at... error periodically · ...
Bug description In our production instance, we are periodically receiving the following error, this happens a handful of times per day, the prisma query that errors out differs. The app is up and r...
inland-turquoise
inland-turquoise2y ago
don't know if this is relevant but it seems appropriate
fascinating-indigo
fascinating-indigo2y ago
works with prisma, pg still no luck
fair-rose
fair-rose2y ago
Seems like pg uses connectionTimeoutMillis
like-gold
like-gold2y ago
Hi guys. I have a colaborator working with me that is having this same issue. Him and I have the same exact code and connection strings, using Kysely. He's using Linux and I'm using Mac, but we both have the same version of NodeJs. He's in Argentina, I'm in Spain and the Neon region is europe. Could this be an issue? The Vercel project is also in europe. This is the error (truncated)
✓ Compiled / in 10s (2450 modules)
Missing `origin` header from a forwarded Server Actions request.
⨯ Error: Connection closed.
...
(stack trace)
...
code: 'ETIMEDOUT',
page: '/',
[errors]: [
Error: connect ETIMEDOUT 3.126.212.11:5432
at createConnectionError (node:net:1634:14)
at Timeout.internalConnectMultipleTimeout (node:net:1685:38)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '3.126.212.11',
port: 5432
},
✓ Compiled / in 10s (2450 modules)
Missing `origin` header from a forwarded Server Actions request.
⨯ Error: Connection closed.
...
(stack trace)
...
code: 'ETIMEDOUT',
page: '/',
[errors]: [
Error: connect ETIMEDOUT 3.126.212.11:5432
at createConnectionError (node:net:1634:14)
at Timeout.internalConnectMultipleTimeout (node:net:1685:38)
at listOnTimeout (node:internal/timers:575:11)
at process.processTimers (node:internal/timers:514:7) {
errno: -110,
code: 'ETIMEDOUT',
syscall: 'connect',
address: '3.126.212.11',
port: 5432
},
extended-salmon
extended-salmon2y ago
@Pedro Enrique first thing I always suggest to people is to use the same connection details with psql. That can really help narrow down where any issues might be
fair-rose
fair-rose2y ago
Increase the connection timeout parameter with your driver. It might help
extended-salmon
extended-salmon2y ago
@ShinyPokemon if this is indeed the issue, I wonder if we should talk about increasing the timeout in our docs for the pg driver
fair-rose
fair-rose2y ago
Yeah, we might want to mention it. I wonder if cold starts increase the change, though TBH I assume it connects to the LB fine first
like-gold
like-gold2y ago
increased to 3000 , same issue. I will ask the engineer to try connecting with psql He was able to connect with Beekeeper Studio, let's see if psql works
fair-rose
fair-rose2y ago
I would try even higher than 3 seconds, just to see.
like-gold
like-gold2y ago
ok, will report back tonight, I'll ping you with anything thx
deep-jade
deep-jade2y ago
I'm having the same issue from Elixir — https://discord.com/channels/1176467419317940276/1212478113397604382 — what's really odd is this used to work — which is making me suspect something broke on Neon's end
extended-salmon
extended-salmon2y ago
Are any of you all anything but the free tier?
deep-jade
deep-jade2y ago
I'm on the Pro tier & I'm using Logical Replication
extended-salmon
extended-salmon2y ago
@Kyle Mathews highly recommend creating a support ticket through the console. You can get specialized 1:1 support
deep-jade
deep-jade2y ago
ok, doing that now
extended-salmon
extended-salmon2y ago
Discord is primarily for community support. We definitely want our paying customers to use the resources that they pay for

Did you find this page helpful?