Search code examples
node.jsoracleoracle-sqldevelopernode-oracledb

Error closing node-oracledb pool connections with Oracle DB and Node.js


I have problems closing the connection to the database in Oracle. First I create the connection without any problems.

  try {
  console.log('Initializing database module');

  await database.initialize();
  } catch (err) {
  console.error(err);

  process.exit(1); // Non-zero failure code
  }


async function initialize() {
  console.log(dbConfig.hrPool);
  const pool = await oracledb.createPool(dbConfig.hrPool);
}

module.exports.initialize = initialize;

when I want to close the connection, the application is waiting without answering anything, so I do it to end the connection

  try {
  console.log('Closing database module');
  console.log(" here 1");
  await database.close();// line  whit problem
  console.log(" here 2");
  } catch (err) {
  console.log('Encountered error', e);

  err = err || e;
  }

async function close() {
  await oracledb.getPool().close();
}

module.exports.close = close;


also note that I use a vpn connection for the database


Solution

  • Review pool.close() documentation:

    1. You probably want to specify a drainTime value otherwise the pool may not actually close.

    2. You may need to add DISABLE_OOB=ON to a sqlnet.ora file