简体   繁体   中英

Node oracledb connection pool not closing before node process termination

Node application when terminating is not closing the db sessions. I am currently using node-cleanup library, but when the pool connections are above a certain number the pool.close() function will take some time to resolve so the node terminates without closing the pool and sessions remain inactive in the db.Have already set proper time outs in oracle DB so that inactive sessions are sniped and cleaned up. But wanted to know is there some way I can block the node process exit so that the pool.close() is resolved.

nodeCleanup(function(exitCode, signal) {
    console.log('Node server exiting with signal : ' + signal);
    console.log('Node server exiting with exitCode : ' + exitCode);
    db.getPool().close();
});

But if I use the below service and then exit the node all db sessions are closed properly.

app.get('/closePool', function(req, res, next) {
    db.getPool().close(function(err) {
        if (err)
            next(err);
        res.send('Pool closed');
    });
})

Have you tried to use the beforeExit event?https://nodejs.org/api/process.html#process_event_beforeexit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM