brianc / node-pg-pool

A connection pool for node-postgres
MIT License
180 stars 64 forks source link

pool not timing out/idling #99

Open InsidiousForce opened 6 years ago

InsidiousForce commented 6 years ago
                            user: db_username,
                            password: db_password,
                            host: db_host,
                            port: db_port',
                            database: db_schema,
                            max: 10, // set pool max size to 10
                            min: 0, // set min pool size to 0
                            idleTimeoutMillis: 10000, // close idle clients after 10 seconds
                            softIdleTimeoutMillis: 10000,
                            evictionRunIntervalMillis: 10000

No matter what we change the values of the last 5 items to (I added the last 2 after no love on the idleTimeoutMills by itself) there is always 1 idle connection to the database left open. Days and days go by and there is still one idle connection left open to the database server. Is there a way to have the pool clean up idle connections down to 0?

Here's the code we're using, Database.connections[host].connection is as above.

Pool init:

    Database.pool = new Pool( Database.connections[host].connection );

    Database.pool.on( 'error', (error, client) => {
        console.log( 'Pool connection error', error );
    });

    Database.pool.connect()
        .then( () => {
            console.log( `Connected to host ${host}.`);
            console.log( JSON.stringify( Database.connections[host] ) );
        })
        .catch( error => {
            console.log( `Error Connecting to host ${host}, retrying in 5 seconds...` );
            console.log( JSON.stringify(error) );
            setTimeout( setConnection, 5000 );
        });
}

Queries:

Database.pool.query( SqlQueries.SetUserSetting, params )
            .then( result => {
                Database.GetUserSetting(userid, key, nodes, callback.bind(this));
            })
            .catch( error => {
                callback({success: false, data: error});
            });
charmander commented 6 years ago

No matter what we change the values of the last 5 items to (I added the last 2 after no love on the idleTimeoutMills by itself) there is always 1 idle connection to the database left open. Days and days go by and there is still one idle connection left open to the database server.

How are you checking? Are you sure it doesn’t come from somewhere else?