question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Connection terminated error with pooling

See original GitHub issue

Hi everybody !

I have a little problem with my code. I’m trying to request my DB to get the pseudo linked with a specific ID. I’m using the pool as recommended with the documentation but I have an error. I think I’m missing something but I don’t know why.

This is my code:

function pseudo_utilisateur(id){
    return new Promise(function(resolve, reject){
        let query = `SELECT pseudo FROM ${Tables.user} WHERE id = $1`;
        pool.connect(function(err, client, done){
            client.query(query, [id],function(err, result){
                done();
                if(err){
                    console.log(err);
                    reject("err");
                }
                else{
                    console.log(result);
                    resolve(result.rows[0].pseudo);
                }
            })
        })
    })
}

and this is the error I received:

Error: Connection terminated
    at Connection.<anonymous> (E:\Cours année 2015 - 2017\Mémoire\mookup\node_modules\pg\lib\client.js:198:29)
    at Object.onceWrapper (events.js:291:19)
    at emitNone (events.js:86:13)
    at Connection.emit (events.js:186:7)
    at Socket.<anonymous> (E:\Cours année 2015 - 2017\Mémoire\mookup\node_modules\pg\lib\connection.js:78:10)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:189:7)
    at TCP._handle.close [as _onclose] (net.js:501:12)

I have read this is a common error when someone uses the client approach. But I don’t think I close the connection before reading the results. If I have well understood, the done() method is to release the client and the result of the request is in the callback of the client. But maybe I’m wrong.

So can someone help me, please ? Thank you very much

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
abenhamdinecommented, Feb 20, 2018

@JulesAU @AkhilGopan @baninaveen again, please open a new issue with reproduction code and the error you see. It doesn’t help to write on a closed issue, which the OP has closed because he has solved his own bug.

0reactions
abenhamdinecommented, Mar 12, 2019

@abenhamdine @JulesAU I started having the same problem, but only with long time queries, i found a possible solution by setting “idleTimeoutMillis” in the “new Pool” constructor, for example to 20000 (the default value is 10000)

My environment is:

* ubuntu: 18.04

* nodejs: 8.11.4

* npm: 6.4.1

* pg: 7.5.0

See node-postgres.com/api/pool#new-pool-config-object-

Please reeopened an issue, don’t feed a closed one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Postgresql Error: connection terminated - Stack Overflow
Here's how I was able to fix it. This means that the client somehow dropped the connection before the server could finish.
Read more >
1623183 - Postgres Connection termination kills services
The script got a little more complicated! The error occurs when the connection dies while the client is checked out of the pool,...
Read more >
Connection Error: Connection ended unexpectedly - Render
... new database and now keep getting a connection terminated error. this ... i added the pool object and acquireConnectionTimeout . i might ......
Read more >
JDBC Connection terminated error - Adobe Support Community
1. Try disabling JDBC pooling entirely. You can do this in the CF Admin by unchecking "Maintain Connections". This will keep you from...
Read more >
Handling java.sql.SQLRecoverableException: Closed ...
SQLRecoverableException: Closed Connection errors ... then the database connection pool (DBCP) or C3PO (if using direct JDBC) is not able to ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found