Skip to content

Commit 70cc565

Browse files
committed
Connection Pool code improvements
1 parent d112fda commit 70cc565

File tree

5 files changed

+28
-44
lines changed

5 files changed

+28
-44
lines changed

lib/errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ adjustErrorXref.set("OCI-22165", [ERR_INVALID_COLL_INDEX_SET, /index \[([0-9]+)\
177177
adjustErrorXref.set("ORA-00028", ERR_CONNECTION_CLOSED);
178178
adjustErrorXref.set("ORA-00600", ERR_CONNECTION_CLOSED);
179179
adjustErrorXref.set("ORA-24338", ERR_INVALID_REF_CURSOR);
180-
adjustErrorXref.set("ORA-24422", ERR_POOL_HAS_BUSY_CONNECTIONS);
181180
adjustErrorXref.set("ORA-25708", ERR_TOKEN_HAS_EXPIRED);
182181

183182
// define mapping for error messages

lib/pool.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,14 @@ class Pool extends EventEmitter {
279279
});
280280
}
281281

282+
// if any connections are still out and the pool is not being force closed,
283+
// throw an exception
284+
if (!forceClose && this._connectionsOut > 0) {
285+
errors.throwErr(errors.ERR_POOL_HAS_BUSY_CONNECTIONS);
286+
}
287+
282288
// close the pool
283-
await this._impl.close({forceClose: forceClose});
289+
await this._impl.close();
284290
this._status = constants.POOL_STATUS_CLOSED;
285291
this.emit('_afterPoolClose');
286292

lib/thin/pool.js

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,25 @@ class ThinPoolImpl extends PoolImpl {
228228
//---------------------------------------------------------------------------
229229
// close pool by destroying available connections
230230
//---------------------------------------------------------------------------
231-
async close(obj) {
231+
async close() {
232+
232233
// clear scheduled job
233234
if (this._schedulerJob) {
234235
clearTimeout(this._schedulerJob);
235236
this._schedulerJob = null;
236237
}
237-
return await this.destroyAllNow(obj);
238+
239+
// destroy all free connections
240+
for (const conn of this._freeConnectionList) {
241+
await this._destroy(conn);
242+
}
243+
244+
// destroy all used connections
245+
for (const conn of this._usedConnectionList) {
246+
await this._destroy(conn);
247+
}
248+
249+
this.eventEmitter.removeAllListeners();
238250
}
239251

240252
//---------------------------------------------------------------------------
@@ -438,33 +450,6 @@ class ThinPoolImpl extends PoolImpl {
438450
this._setScheduler();
439451
}
440452

441-
//---------------------------------------------------------------------------
442-
// destroyAllNow()
443-
//
444-
// called during pool close operation and close any available connection
445-
// available in connection pool
446-
//---------------------------------------------------------------------------
447-
async destroyAllNow(obj) {
448-
let conn;
449-
while (this._freeConnectionList.length !== 0) {
450-
conn = this._freeConnectionList.pop();
451-
await this._destroy(conn);
452-
}
453-
454-
if (obj.forceClose) {
455-
for (const item of this._usedConnectionList) {
456-
await this._destroy(item);
457-
this._usedConnectionList.delete(item);
458-
}
459-
}
460-
461-
if (this._usedConnectionList.size !== 0) {
462-
errors.throwErr(errors.ERR_POOL_HAS_BUSY_CONNECTIONS);
463-
}
464-
465-
this.eventEmitter.removeAllListeners();
466-
}
467-
468453
//---------------------------------------------------------------------------
469454
// _generateConnectionClass()
470455
//

src/njsBaton.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ bool njsBaton_getJsonNodeValue(njsBaton *baton, dpiJsonNode *node,
425425
napi_value key, temp;
426426
dpiJsonArray *array;
427427
dpiJsonObject *obj;
428+
double temp_double;
428429
uint32_t i;
429430

430431
// null is a special case
@@ -469,8 +470,9 @@ bool njsBaton_getJsonNodeValue(njsBaton *baton, dpiJsonNode *node,
469470
NULL, value))
470471
return true;
471472
case DPI_ORACLE_TYPE_NUMBER:
472-
NJS_CHECK_NAPI(env, napi_create_double(env, node->value->asDouble,
473-
value))
473+
temp_double = (node->nativeTypeNum == DPI_NATIVE_TYPE_DOUBLE) ?
474+
node->value->asDouble : node->value->asFloat;
475+
NJS_CHECK_NAPI(env, napi_create_double(env, temp_double, value))
474476
return true;
475477
case DPI_ORACLE_TYPE_DATE:
476478
case DPI_ORACLE_TYPE_TIMESTAMP:

src/njsPool.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2015, 2022, Oracle and/or its affiliates.
1+
// Copyright (c) 2015, 2023, Oracle and/or its affiliates.
22

33
//-----------------------------------------------------------------------------
44
//
@@ -108,17 +108,11 @@ const njsClassDef njsClassDefPool = {
108108
//-----------------------------------------------------------------------------
109109
// njsPool_close()
110110
// Close the pool.
111-
//
112-
// PARAMETERS
113-
// - options
114111
//-----------------------------------------------------------------------------
115-
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_close, 1, NULL)
112+
NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_close, 0, NULL)
116113
{
117114
njsPool *pool = (njsPool*) baton->callingInstance;
118115

119-
if (!njsUtils_getNamedPropertyBool(env, args[0], "forceClose",
120-
&baton->force))
121-
return false;
122116
baton->accessTokenCallback = pool->accessTokenCallback;
123117
pool->accessTokenCallback = NULL;
124118
baton->dpiPoolHandle = pool->handle;
@@ -134,16 +128,14 @@ NJS_NAPI_METHOD_IMPL_ASYNC(njsPool_close, 1, NULL)
134128
//-----------------------------------------------------------------------------
135129
static bool njsPool_closeAsync(njsBaton *baton)
136130
{
137-
dpiPoolCloseMode mode = (baton->force) ? DPI_MODE_POOL_CLOSE_FORCE :
138-
DPI_MODE_POOL_CLOSE_DEFAULT;
139131
njsPool *pool = (njsPool*) baton->callingInstance;
140132

141133
pool->accessTokenCallback = baton->accessTokenCallback;
142134
if (baton->accessTokenCallback) {
143135
njsTokenCallback_stopNotifications(baton->accessTokenCallback);
144136
baton->accessTokenCallback = NULL;
145137
}
146-
if (dpiPool_close(baton->dpiPoolHandle, mode) < 0) {
138+
if (dpiPool_close(baton->dpiPoolHandle, DPI_MODE_POOL_CLOSE_FORCE) < 0) {
147139
njsBaton_setErrorDPI(baton);
148140
pool->handle = baton->dpiPoolHandle;
149141
baton->dpiPoolHandle = NULL;

0 commit comments

Comments
 (0)