Skip to content
This repository was archived by the owner on Dec 30, 2019. It is now read-only.
This repository was archived by the owner on Dec 30, 2019. It is now read-only.

Fails to reconnect after invoking end() #58

@vitaly-t

Description

@vitaly-t

We call end() on the pool in order to shut down all the connections within the pool.

However, doing so prevents us from being able to use the object any longer.

Any attempt of calling .connect after .end() was called once results in the following error:

pool is draining and cannot accept work

Below is a complete test application:

'use strict';

var pg = require('pg');

var config = {
    database: 'newone',
    port: 5433,
    user: 'postgres'
};

var pool = new pg.Pool(config);

function test1() {
    pool.connect((err, client, done) => {
        if (err) {
            console.log('Error Connecting:', err);
            return;
        }
        client.query('select count(*) from users', (err, data) => {
            if (err) {
                console.log('Query Error:', err);
            } else {
                console.log('DATA:', data.rows);
            }
            done();
            pool.end();
            test2();
        });
    });
}

function test2() {
    pool.connect((err, client, done) => {
        if (err) {
            console.log('Error Connecting:', err);
            return;
        }
        client.query('select count(*) from users', (err, data) => {
            if (err) {
                console.log('Query Error:', err);
            } else {
                console.log('DATA:', data.rows);
            }
            done();
            pool.end();
        });
    });
}

test1();

test1 ends successfully, but in test2 it always throws that error on this line:

console.log('Error Connecting:', err);
//=> pool is draining and cannot accept work

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions