File tree 2 files changed +37
-9
lines changed
2 files changed +37
-9
lines changed Original file line number Diff line number Diff line change @@ -783,11 +783,7 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface {
783
783
return ;
784
784
}
785
785
786
- try {
787
- await this . _createSessions ( needed ) ;
788
- } catch ( e ) {
789
- this . emit ( 'error' , e ) ;
790
- }
786
+ await this . _createSessions ( needed ) ;
791
787
}
792
788
793
789
/**
@@ -993,7 +989,24 @@ export class SessionPool extends EventEmitter implements SessionPoolInterface {
993
989
const pings = sessions . map ( session => this . _ping ( session ) ) ;
994
990
995
991
await Promise . all ( pings ) ;
996
- return this . _fill ( ) ;
992
+ try {
993
+ await this . _fill ( ) ;
994
+ } catch ( error ) {
995
+ // Ignore `Database not found` error. This allows a user to call instance.database('db-name')
996
+ // for a database that does not yet exist with SessionPoolOptions.min > 0.
997
+ const err = error as ServiceError ;
998
+ if (
999
+ isDatabaseNotFoundError ( err ) ||
1000
+ isInstanceNotFoundError ( err ) ||
1001
+ isCreateSessionPermissionError ( err ) ||
1002
+ isDefaultCredentialsNotSetError ( err ) ||
1003
+ isProjectIdNotSetInEnvironmentError ( err )
1004
+ ) {
1005
+ return ;
1006
+ }
1007
+ this . emit ( 'error' , err ) ;
1008
+ }
1009
+ return ;
997
1010
}
998
1011
999
1012
/**
Original file line number Diff line number Diff line change @@ -953,12 +953,10 @@ describe('SessionPool', () => {
953
953
954
954
stub . rejects ( error ) ;
955
955
956
- sessionPool . once ( 'error' , err => {
956
+ sessionPool . _fill ( ) . catch ( err => {
957
957
assert . strictEqual ( err , error ) ;
958
958
done ( ) ;
959
959
} ) ;
960
-
961
- sessionPool . _fill ( ) ;
962
960
} ) ;
963
961
} ) ;
964
962
@@ -1286,6 +1284,23 @@ describe('SessionPool', () => {
1286
1284
1287
1285
assert . strictEqual ( fillStub . callCount , 1 ) ;
1288
1286
} ) ;
1287
+
1288
+ it ( 'should not throw error when database not found' , async ( ) => {
1289
+ const fakeSessions = [ createSession ( ) ] ;
1290
+ sandbox . stub ( sessionPool , '_getIdleSessions' ) . returns ( fakeSessions ) ;
1291
+
1292
+ const error = {
1293
+ code : grpc . status . NOT_FOUND ,
1294
+ message : 'Database not found' ,
1295
+ } as grpc . ServiceError ;
1296
+ sandbox . stub ( sessionPool , '_fill' ) . rejects ( error ) ;
1297
+
1298
+ try {
1299
+ await sessionPool . _pingIdleSessions ( ) ;
1300
+ } catch ( err ) {
1301
+ assert . ifError ( err ) ;
1302
+ }
1303
+ } ) ;
1289
1304
} ) ;
1290
1305
1291
1306
describe ( '_release' , ( ) => {
You can’t perform that action at this time.
0 commit comments