porsager / postgres

Postgres.js - The Fastest full featured PostgreSQL client for Node.js, Deno, Bun and CloudFlare
The Unlicense
7.09k stars 259 forks source link

devcontainer and vpn - sql throws ECONNRESET #730

Open lucider5 opened 8 months ago

lucider5 commented 8 months ago
const sql = postgres() // credentials loaded from env
await sql`SELECT 1`

I can only run this command under the following situations:

It does not work for:

It results in an ECONNRESET error after a few minutes. Interestingly, "pg" work in all 4 situations.

The database is in a corporate network. The vpn is zscaler. Certificates are installed in the devcontainer.

porsager commented 8 months ago

How does the various connection details look?

lucider5 commented 8 months ago

I am not sure if thats what you wanted to know. I use the same configuration for all 4 situations. The env variables I provide are:

PGHOST=xxx PGPORT=xxx PGDATABASE=xxx PGUSERNAME=xxx PGPASSWORD=xxx

Already tried:

porsager commented 8 months ago

Right, so you're relying on the env variables. Are you connecting to hostnames or ips?

lucider5 commented 8 months ago

I connect to ip

porsager commented 8 months ago

Hmm. Thought it could have been an IPv 4/6 issue, but no.

Well without more info there's not really anything to go by. Are you trying the most minimal setup ensuring no differences when comparing to pg?

lucider5 commented 8 months ago

Yes, I am using the most minimal setup. Maybe the error msg helps?

TypeError: Cannot redefine property: query
    at Function.defineProperties (<anonymous>)
    at queryError (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:279:16)
    at errored (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:276:21)
    at Socket.error (webpack-internal:///(action-browser)/./node_modules/postgres/src/connection.js:270:9)
    at Socket.emit (node:events:515:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20)
    at TCP.callbackTrampoline (node:internal/async_hooks:130:17)
    at cachedError (webpack-internal:///(action-browser)/./node_modules/postgres/src/query.js:141:25)
    at new Query (webpack-internal:///(action-browser)/./node_modules/postgres/src/query.js:29:79)
    at Module.sql (webpack-internal:///(action-browser)/./node_modules/postgres/src/index.js:103:67)
    at fastPathExist (webpack-internal:///(action-browser)/./app/lib/api.ts:11:55) {
  errno: -104,
  code: 'ECONNRESET',
  syscall: 'read'
}
galah92 commented 6 months ago

I'm seeing the same error with Cloud Run connecting to Cloud SQL on GCP.

nir-bar-zvi commented 4 months ago

@lucider5 did you reach any conclusion on this?

SampaioLeal commented 4 weeks ago

im having the same problem:

TypeError: Cannot redefine property: query
    at Function.defineProperties (<anonymous>)
    at queryError (file:///builds/sancor/ffc-service/node_modules/postgres/src/connection.js:[38](https://gitlab.eurekalabs.com.br/sancor/ffc-service/-/jobs/531696#L38)8:12)
    at errored (file:///builds/sancor/ffc-service/node_modules/postgres/src/connection.js:384:17)
    at TLSSocket.data (file:///builds/sancor/ffc-service/node_modules/postgres/src/connection.js:318:9)
    at TLSSocket.emit (node:events:519:28)
    at addChunk (node:internal/streams/readable:559:12)
    at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
    at Readable.push (node:internal/streams/readable:[39](https://gitlab.eurekalabs.com.br/sancor/ffc-service/-/jobs/531696#L39)0:5)
    at TLSWrap.onStreamRead (node:internal/stream_base_commons:191:23)
Node.js v20.15.0

but the error dont give me more details

"postgres": "^3.4.4" "drizzle-orm": "^0.31.2"

it seems like the error was with RDS wrong password, but i was able to get this info after changing to pg