node-pg-pool icon indicating copy to clipboard operation
node-pg-pool copied to clipboard

pool not timing out/idling

Open InsidiousForce opened this issue 7 years ago • 1 comments

                            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});
            });

InsidiousForce avatar Apr 11 '18 00:04 InsidiousForce

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?

charmander avatar Apr 19 '18 02:04 charmander