node-postgres
node-postgres copied to clipboard
Can not close connection without an exception
I try end a connection when end all tasks, by example:
const { Client } = require('pg');
const client = new Client({ .... });
client.connect()
.then(() => client.query('SELECT 1'))
.then(() => client.end());
The results is:
user@pc:~/project$ npm start
> [email protected]
> node index.js
(node:293246) [DEP0111] DeprecationWarning: Access to process.binding('http_parser') is deprecated.
(Use `node --trace-deprecation ...` to show where the warning was created)
/home/user/project/node_modules/pg/lib/client.js:132
const error = this._ending ? new Error('Connection terminated') : new Error('Connection terminated unexpectedly')
^
Error: Connection terminated
at Connection.<anonymous> (/home/user/project/node_modules/pg/lib/client.js:132:36)
at Object.onceWrapper (node:events:627:28)
at Connection.emit (node:events:525:35)
at Socket.<anonymous> (/home/user/project/node_modules/pg/lib/connection.js:63:12)
at Socket.emit (node:events:513:28)
at TCP.<anonymous> (node:net:313:12)
Node.js v18.12.1
The versions:
user@pc:~/project$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.2 LTS
Release: 22.04
Codename: jammy
user@pc:~/project$ cat package.json | grep pg
"pg": "^8.11.0",
user@pc:~/project$ node -v
v18.12.1
PostgreSQL version: 12.14.
Probably a duplicate of https://github.com/brianc/node-postgres/issues/1833