@@ -492,6 +492,7 @@ export class Bigtable {
492492 static Cluster : Cluster ;
493493 _metricsConfigManager : ClientSideMetricsConfigManager ;
494494 admin : admin . BigtableAdmin ;
495+ closed = false ;
495496
496497 constructor ( options : BigtableOptions = { } ) {
497498 // Determine what scopes are needed.
@@ -909,6 +910,17 @@ export class Bigtable {
909910 let gaxStream : gax . CancellableStream ;
910911 let stream : AbortableDuplex ;
911912
913+ if ( this . closed ) {
914+ callback ?.( {
915+ name : 'Closed' ,
916+ message : 'Bigtable internal client is closed' ,
917+ code : grpc . status . ABORTED ,
918+ details : 'Bigtable internal client is closed' ,
919+ metadata : new grpc . Metadata ( ) ,
920+ } ) ;
921+ return ;
922+ }
923+
912924 const prepareGaxRequest = (
913925 callback : ( err : Error | null , fn ?: Function ) => void ,
914926 ) => {
@@ -1026,11 +1038,22 @@ export class Bigtable {
10261038 * Close all bigtable clients. New requests will be rejected but it will not
10271039 * kill connections with pending requests.
10281040 */
1029- close ( ) : Promise < void [ ] > {
1041+ async close ( ) : Promise < void [ ] > {
1042+ // Close all of the clients.
10301043 const combined = Object . keys ( this . api ) . map ( clientType =>
10311044 this . api [ clientType ] . close ( ) ,
10321045 ) ;
1033- return Promise . all ( combined ) ;
1046+ const results = await Promise . all ( combined ) ;
1047+
1048+ // Clear them out of our cache.
1049+ Object . keys ( this . api ) . forEach ( clientType => {
1050+ delete this . api [ clientType ] ;
1051+ } ) ;
1052+
1053+ // Mark as closed.
1054+ this . closed = true ;
1055+
1056+ return results ;
10341057 }
10351058
10361059 /**
0 commit comments