Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ConnectionError: Connection terminated due to connection timeout in Node 14.0.0 #173

@ByAgenT

Description

@ByAgenT

After upgrading Node version to 14.0.0, slonik cannot connect to database and results in throwing ConnectionError: Connection terminated due to connection timeout error.

OS: macOS Catalina v10.15.4
Node: 14.0.0 (brew)
slonik: 22.4.4
DB (Docker container): PostgreSQL 12.2 (Debian 12.2-2.pgdg100+1)

Script example:

const slonik = require('slonik');

const createPool = slonik.createPool;
const sql = slonik.sql;

const pool = createPool(
  'postgres://<username>:<password>@localhost:5432/<dbname>'
);
pool
  .connect(async (connection) => {
    try {
      await connection.query(sql`SELECT 1`);
      console.log('query executed');
    } catch (error) {
      console.log('error in query');
      console.error(error);
    }
  })
  .catch((error) => {
    console.log('error in connect');
    console.error(error);
  });

Expected Behavior

Get query executed message in console.

Current Behavior

Console:

error in connect
ConnectionError: Connection terminated due to connection timeout
    at createConnection (<path_removed>/slonik-n-14-test/node_modules/slonik/dist/factories/createConnection.js:69:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at runNextTicks (internal/process/task_queues.js:66:3)
    at listOnTimeout (internal/timers.js:518:9)
    at processTimers (internal/timers.js:492:7)

Steps to Reproduce

  1. Install Node 14.0.0
  2. Install slonik 22.4.4
  3. Execute script from description

Logs

Logs from the same script running on Node v12.16.2

> node -v
v12.16.2
> ROARR_LOG=true node index.js
{"context":{"package":"slonik","poolId":"01E70ANTGERRQD5RV8FHA81SVA","logLevel":20},"message":"pg-native module is not found","sequence":0,"time":1588075358738,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70ANTGERRQD5RV8FHA81SVA","logLevel":30},"message":"using JavaScript bindings; pg-native not found","sequence":1,"time":1588075358739,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70ANTGERRQD5RV8FHA81SVA","logLevel":20,"processId":86,"stats":{"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0}},"message":"created a new client connection","sequence":2,"time":1588075358778,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70ANTGERRQD5RV8FHA81SVA","logLevel":20,"processId":86,"stats":{"idleConnectionCount":0,"totalConnectionCount":1,"waitingRequestCount":0}},"message":"client is checked out from the pool","sequence":3,"time":1588075358779,"version":"1.0.0"}
query executed
{"context":{"package":"slonik","poolId":"01E70ANTGERRQD5RV8FHA81SVA","logLevel":20,"processId":86,"stats":{"idleConnectionCount":0,"totalConnectionCount":0,"waitingRequestCount":0}},"message":"client connection is closed and removed from the client pool","sequence":4,"time":1588075358849,"version":"1.0.0"}

Logs from the script execution in Node 14.0.0

> node -v
v14.0.0
> ROARR_LOG=true node index.js
{"context":{"package":"slonik","poolId":"01E70AM7FBCBHCD8K8VN2P6JTM","logLevel":20},"message":"pg-native module is not found","sequence":0,"time":1588075306479,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70AM7FBCBHCD8K8VN2P6JTM","logLevel":30},"message":"using JavaScript bindings; pg-native not found","sequence":1,"time":1588075306481,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70AM7FBCBHCD8K8VN2P6JTM","logLevel":50,"error":{"name":"Error","message":"Connection terminated due to connection timeout","stack":"Error: Connection terminated due to connection timeout\n    at Connection.<anonymous> (<path_removed>/slonik-n-14-test/node_modules/pg/lib/client.js:255:9)\n    at Object.onceWrapper (events.js:421:28)\n    at Connection.emit (events.js:315:20)\n    at Connection.EventEmitter.emit (domain.js:485:12)\n    at Socket.<anonymous> (<path_removed>/slonik-n-14-test/node_modules/pg/lib/connection.js:78:10)\n    at Socket.emit (events.js:315:20)\n    at Socket.EventEmitter.emit (domain.js:485:12)\n    at emitCloseNT (net.js:1656:8)\n    at processTicksAndRejections (internal/process/task_queues.js:83:21)\n    at runNextTicks (internal/process/task_queues.js:66:3)\n    at listOnTimeout (internal/timers.js:518:9)\n    at processTimers (internal/timers.js:492:7)"},"remainingConnectionRetryLimit":2},"message":"cannot establish connection","sequence":2,"time":1588075311517,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70AM7FBCBHCD8K8VN2P6JTM","logLevel":30},"message":"retrying connection","sequence":3,"time":1588075311517,"version":"1.0.0"}
{"context":{"package":"slonik","poolId":"01E70AM7FBCBHCD8K8VN2P6JTM","logLevel":50,"error":{"name":"Error","message":"Connection terminated due to connection timeout","stack":"Error: Connection terminated due to connection timeout\n    at Connection.<anonymous> (<path_removed>/slonik-n-14-test/node_modules/pg/lib/client.js:255:9)\n    at Object.onceWrapper (events.js:421:28)\n    at Connection.emit (events.js:315:20)\n    at Connection.EventEmitter.emit (domain.js:485:12)\n    at Socket.<anonymous> (<path_removed>/slonik-n-14-test/node_modules/pg/lib/connection.js:78:10)\n    at Socket.emit (events.js:315:20)\n    at Socket.EventEmitter.emit (domain.js:485:12)\n    at emitCloseNT (net.js:1656:8)\n    at processTicksAndRejections (internal/process/task_queues.js:83:21)\n    at runNextTicks (internal/process/task_queues.js:66:3)\n    at listOnTimeout (internal/timers.js:518:9)\n    at processTimers (internal/timers.js:492:7)"},"remainingConnectionRetryLimit":1},"message":"cannot establish connection","sequence":4,"time":1588075316520,"version":"1.0.0"}
error in connect
ConnectionError: Connection terminated due to connection timeout
    at createConnection (<path_removed>/slonik-n-14-test/node_modules/slonik/dist/factories/createConnection.js:69:15)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)
    at runNextTicks (internal/process/task_queues.js:66:3)
    at listOnTimeout (internal/timers.js:518:9)
    at processTimers (internal/timers.js:492:7)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions