@@ -28,6 +28,12 @@ export type PoolMetricsType = {
2828 SessionPoolCount : number ;
2929} ;
3030
31+ enum SessionPoolManagerState {
32+ LIVE = 'LIVE' ,
33+ PENDING = 'PENDING' ,
34+ DOWN = 'DOWN' ,
35+ }
36+
3137/**
3238 * Global Instances
3339 */
@@ -512,6 +518,9 @@ class PuppeteerCapsule {
512518 *
513519 */
514520class SessionPoolManager < T = unknown > {
521+ // State of session pool manager
522+ private state : SessionPoolManagerState = SessionPoolManagerState . LIVE ;
523+
515524 constructor (
516525 private poolId : number ,
517526 private browser : PuppeteerCapsule ,
@@ -529,13 +538,26 @@ class SessionPoolManager<T = unknown> {
529538 return await this . pool . release ( session ) ;
530539 }
531540
532- async close ( ) {
541+ // Do not use JS getter, setter
542+ public getState ( ) {
543+ return this . state ;
544+ }
545+
546+ private setState ( state : SessionPoolManagerState ) {
547+ this . state = state ;
548+ }
549+
550+ public async close ( ) {
533551 await this . pool . drain ( ) ;
534552 await this . pool . clear ( ) ;
535553 await this . browser . closeBrowser ( ) ;
536554 }
537555
538556 async rebootSessionPoolPuppeteer ( ) {
557+ if ( this . state !== SessionPoolManagerState . LIVE ) {
558+ return ;
559+ }
560+ this . setState ( SessionPoolManagerState . PENDING ) ;
539561 // Wait until all session is released
540562 while ( this . pool . borrowed >= 1 ) {
541563 await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
@@ -556,6 +578,7 @@ class SessionPoolManager<T = unknown> {
556578 logger . info (
557579 `Reboot session pool --- PID: ${ browserProcessId } --- Pool ID: ${ this . poolId } ` ,
558580 ) ;
581+ this . setState ( SessionPoolManagerState . LIVE ) ;
559582 return browserProcessId ;
560583 }
561584}
0 commit comments