Skip to content

Connecting node-pg pool to neon postgres database with sslmode=require connection string. #1889

Open
@dbauszus-glx

Description

@dbauszus-glx

Describe the bug

We are trying to connect the node-pg library to a Neon Postgres database.

We use node-pg version 8.16. https://www.npmjs.com/package/pg

The connection is configured via connection string from the Neon dashboard which requires sslmode.

    const pool = new Pool({
      connectionString: 'postgresql://dbauszus:***@ep-curly-base-242741.eu-central-1.aws.neon.tech/neondb?sslmode=require',
      connectionTimeoutMillis: 5000,
      dbs: 'NEON',
      idleTimeoutMillis: 30000, // 5 seconds
      keepAlive: true, // 30 seconds
      max: 20, // Maximum number of clients in the pool
    });

    client = await pool.connect();

The connection seems to fail when attempting to request the SSL certificate. at Connection.requestSsl (file:///home/dbauszus-glx/xyz_dev/node_modules/pg/lib/connection.js#cjs:121:33)

Below is the full stack log from the terminal.

{
  err: Error: Connection terminated due to connection timeout
      at eval (/home/dbauszus-glx/xyz_dev/node_modules/pg-pool/index.js:45:11)
      at <anonymous> (https://xyzdev-mrwe.w-credentialless-staticblitz.com/blitz.55edb8f4.js:31:28929) {
    [cause]: Error: Connection terminated unexpectedly
        at Connection.eval (/home/dbauszus-glx/xyz_dev/node_modules/pg/lib/client.js:136:73)
        at Object.onceWrapper (node:events:30:8244)
        at Connection.emit (node:events:30:11034)
        at Socket.eval (/home/dbauszus-glx/xyz_dev/node_modules/pg/lib/connection.js:62:12)
        at Socket.emit (node:events:30:11034)
        at <anonymous> (node:net:292:3722)
        at <anonymous> (https://xyzdev-mrwe.w-credentialless-staticblitz.com/blitz.55edb8f4.js:31:295130)
  },
  pool: 'NEON',
  query: '\n' +
    '    SELECT\n' +
    '      id AS id\n' +
    '      , ST_AsText(geom_3857) AS geometry\n' +
    '      FROM scratch\n' +
    '      WHERE TRUE AND geom_3857 IS NOT NULL  ;',
  retry: 1,
  variables: []
}
TypeError: Cannot perform Construct on a detached ArrayBuffer
    at new Uint8Array (<anonymous>)
    at new FastBuffer (https://xyzdev-mrwe.w-credentialless-staticblitz.com/builtins.97a3df4f.js:55:12767)
    at allocate (https://xyzdev-mrwe.w-credentialless-staticblitz.com/builtins.97a3df4f.js:19:5565)
    at Buffer.allocUnsafe (https://xyzdev-mrwe.w-credentialless-staticblitz.com/builtins.97a3df4f.js:19:5621)
    at Object.requestSsl (file:///home/dbauszus-glx/xyz_dev/node_modules/pg-protocol/dist/serializer.js#cjs:19:29)
    at Connection.requestSsl (file:///home/dbauszus-glx/xyz_dev/node_modules/pg/lib/connection.js#cjs:121:33)
    at Connection.eval (file:///home/dbauszus-glx/xyz_dev/node_modules/pg/lib/client.js#cjs:123:13)
    at Connection.emit (https://xyzdev-mrwe.w-credentialless-staticblitz.com/builtins.97a3df4f.js:30:11034)
    at Socket.eval (file:///home/dbauszus-glx/xyz_dev/node_modules/pg/lib/connection.js#cjs:49:12)
    at Object.onceWrapper (https://xyzdev-mrwe.w-credentialless-staticblitz.com/builtins.97a3df4f.js:30:8244)

Link to the blitz that caused the error

https://stackblitz.com/~/github.com/dbauszus-glx/xyz_dev?file=.env&layers=true

Steps to reproduce

Unfortunately this can only be reproduced with a valid Neon connection string which I can not share here.

Expected behavior

We would expect the node-pg library to connect to the defined pool with SSL.

Parity with Local

Screenshots

No response

Platform

Version = 1.84.0
Hash = 3b0b7194bc6b567c2eaf4c96a5759098469dcf59
WebContainer = 55edb8f4

Browser name  = Chrome
Full version  = 136.0.0.0
Major version = 136
navigator.appName = Netscape
navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36
performance.memory = {
  "totalJSHeapSize": 128299247,
  "usedJSHeapSize": 122043799,
  "jsHeapSizeLimit": 4294705152
}

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions