Skip to content

Commit f55c134

Browse files
committed
Added internal _closing flag in connection object
1 parent 3ceecaa commit f55c134

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

lib/connection.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,20 @@ async function close(a1) {
172172
nodbUtil.assert(nodbUtil.isObject(a1), 'NJS-005', 1);
173173
options = a1;
174174
}
175-
await this._close(options);
175+
176+
// If already in the process of closing, throw an error instead of doing
177+
// a roundtrip
178+
if (this._closing) {
179+
throw new Error (nodbUtil.getErrorMessage('NJS-003'));
180+
}
181+
182+
this._closing = true;
183+
try {
184+
await this._close(options);
185+
} finally {
186+
this._closing = false;
187+
}
188+
176189
for (const cls of Object.values(this._dbObjectClasses)) {
177190
cls.prototype.constructor = Object;
178191
cls.prototype = null;
@@ -461,6 +474,7 @@ class Connection extends EventEmitter {
461474
this._dbObjectClasses = {};
462475
this._requestQueue = [];
463476
this._inProgress = false;
477+
this._closing = false;
464478
}
465479

466480
// extend class with promisified functions
@@ -548,7 +562,7 @@ class Connection extends EventEmitter {
548562
// This is a synchronous call.
549563
//---------------------------------------------------------------------------
550564
isHealthy() {
551-
return this._isHealthy();
565+
return (!this._closing && this._isHealthy());
552566
}
553567

554568

0 commit comments

Comments
 (0)