Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Njs 040 fix #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
17 changes: 16 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ exports.createPool = async (poolName) => {
}
};

exports.connect = async (poolName) => {
/**
*
* @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);
Expand All @@ -74,6 +80,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 >= 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);
}
console.error("Oracle Adapter: Error while retrieving a connection", err);
throw new Error(err.message);
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down