File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -172,7 +172,20 @@ async function close(a1) {
172
172
nodbUtil . assert ( nodbUtil . isObject ( a1 ) , 'NJS-005' , 1 ) ;
173
173
options = a1 ;
174
174
}
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
+
176
189
for ( const cls of Object . values ( this . _dbObjectClasses ) ) {
177
190
cls . prototype . constructor = Object ;
178
191
cls . prototype = null ;
@@ -461,6 +474,7 @@ class Connection extends EventEmitter {
461
474
this . _dbObjectClasses = { } ;
462
475
this . _requestQueue = [ ] ;
463
476
this . _inProgress = false ;
477
+ this . _closing = false ;
464
478
}
465
479
466
480
// extend class with promisified functions
@@ -548,7 +562,7 @@ class Connection extends EventEmitter {
548
562
// This is a synchronous call.
549
563
//---------------------------------------------------------------------------
550
564
isHealthy ( ) {
551
- return this . _isHealthy ( ) ;
565
+ return ( ! this . _closing && this . _isHealthy ( ) ) ;
552
566
}
553
567
554
568
You can’t perform that action at this time.
0 commit comments