From b4d6aa3d63135210ed2879b9f87805f15687fec5 Mon Sep 17 00:00:00 2001 From: Yaseen Al Mufti Date: Mon, 12 Dec 2022 09:52:04 -0500 Subject: [PATCH 1/3] Fix for NJS-040 Issue --- index.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index e3fb9a4..6351f57 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,7 @@ exports.createPool = async (poolName) => { } }; -exports.connect = async (poolName) => { +exports.connect = async (poolName, retryCount = 0) => { try { if (!pools[poolName]) { await this.createPool(poolName); @@ -74,6 +74,15 @@ exports.connect = async (poolName) => { console.debug(`Oracle Adapter: Successfully retrieved a connection from ${poolName} pool`); return connection; } catch (err) { + if (JSON.stringify(err).includes('NJS-040') && retryCount <= 2) { + console.error(`Oracle Adapter: Getting pool(${poolAlias}) connection timedout.`); + promises = {}; + pools = {}; + console.debug(`Oracle Adapter: Closing pool ${poolAlias}.`); + await oracledb.getPool(poolName).close(0); + console.debug(`Oracle Adapter: Retrying to connect to ${poolAlias}.`); + return this.connect(poolName, retryCount + 1); + } console.error("Oracle Adapter: Error while retrieving a connection", err); throw new Error(err.message); } From 8ebe8028aecceb619d47d864590eac09e2414a52 Mon Sep 17 00:00:00 2001 From: Yaseen Al Mufti Date: Mon, 12 Dec 2022 10:05:28 -0500 Subject: [PATCH 2/3] version increment and changelog --- README.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5abf043..d109acb 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,9 @@ If you wish to use NVM to maintain parallel Node installations, ensure that it d ## References - https://oracle.github.io/node-oracledb/INSTALL.html#quickstart + +### Changelog + +# v1.0.2 +Added auto drop and create pool when getting connection timedout +to fix NJS-040 issue. diff --git a/package.json b/package.json index ded43ef..57aad11 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@softrams/nodejs-oracle-connector", - "version": "1.0.1", + "version": "1.0.2", "description": "Database connector wrapper to work with Oracle database from nodejs applications", "main": "index.js", "scripts": { From ec61edd442c83c87f3687a2a6430b0e2e1a709c6 Mon Sep 17 00:00:00 2001 From: Yaseen Al Mufti Date: Mon, 12 Dec 2022 10:11:48 -0500 Subject: [PATCH 3/3] Added definitions for function --- index.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 6351f57..40bf638 100644 --- a/index.js +++ b/index.js @@ -65,7 +65,13 @@ exports.createPool = async (poolName) => { } }; -exports.connect = async (poolName, retryCount = 0) => { +/** + * + * @param {string} poolName Connection pool name/alias + * @param {number} retryCount Amount of retries. Default = 2 + * @returns {oracledb.Connection} + */ +exports.connect = async (poolName, retryCount = 2) => { try { if (!pools[poolName]) { await this.createPool(poolName); @@ -74,14 +80,14 @@ exports.connect = async (poolName, retryCount = 0) => { console.debug(`Oracle Adapter: Successfully retrieved a connection from ${poolName} pool`); return connection; } catch (err) { - if (JSON.stringify(err).includes('NJS-040') && retryCount <= 2) { + if (JSON.stringify(err).includes('NJS-040') && retryCount >= 0) { console.error(`Oracle Adapter: Getting pool(${poolAlias}) connection timedout.`); promises = {}; pools = {}; console.debug(`Oracle Adapter: Closing pool ${poolAlias}.`); await oracledb.getPool(poolName).close(0); console.debug(`Oracle Adapter: Retrying to connect to ${poolAlias}.`); - return this.connect(poolName, retryCount + 1); + return this.connect(poolName, retryCount - 1); } console.error("Oracle Adapter: Error while retrieving a connection", err); throw new Error(err.message);