postgres icon indicating copy to clipboard operation
postgres copied to clipboard

devcontainer and vpn - sql throws ECONNRESET

Open stefan-huck opened this issue 1 year ago • 9 comments

const sql = postgres() // credentials loaded from env
await sql`SELECT 1`

I can only run this command under the following situations:

  • On-site and devcontainer
  • On-site and local machine
  • Homeoffice/VPN and local machine

It does not work for:

  • Homeoffice/VPN and devcontainer

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.

stefan-huck avatar Nov 14 '23 09:11 stefan-huck

How does the various connection details look?

porsager avatar Nov 14 '23 09:11 porsager

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:

  • postgres({ ssl: { rejectUnauthorized: false } })
  • tried connection by url string "postgres://username:pass[...]" which also results in not working for VPN & devcontainer

stefan-huck avatar Nov 14 '23 11:11 stefan-huck

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

porsager avatar Nov 14 '23 12:11 porsager

I connect to ip

stefan-huck avatar Nov 14 '23 16:11 stefan-huck

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?

porsager avatar Nov 14 '23 16:11 porsager

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'
}

stefan-huck avatar Nov 14 '23 19:11 stefan-huck

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

galah92 avatar Jan 05 '24 09:01 galah92

@lucider5 did you reach any conclusion on this?

nir-bar-zvi avatar Mar 10 '24 09:03 nir-bar-zvi

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

SampaioLeal avatar Jun 29 '24 02:06 SampaioLeal