@@ -45,12 +45,13 @@ export class DefinedSchemas {
4545 }
4646
4747 async execute ( ) {
48+ let timeout ;
4849 try {
4950 // Set up a time out in production
5051 // if we fail to get schema
5152 // pm2 or K8s and many other process managers will try to restart the process
5253 // after the exit
53- const timeout = setTimeout ( ( ) => {
54+ timeout = setTimeout ( ( ) => {
5455 if ( process . env . NODE_ENV === 'production' ) process . exit ( 1 ) ;
5556 } , 20000 ) ;
5657 // Hack to force session schema to be created
@@ -60,13 +61,14 @@ export class DefinedSchemas {
6061 await Promise . all ( this . localSchemas . map ( async localSchema => this . saveOrUpdate ( localSchema ) ) ) ;
6162 await this . enforceCLPForNonProvidedClass ( ) ;
6263 } catch ( e ) {
63- if ( this . retries <= this . maxRetries ) {
64+ if ( timeout ) clearTimeout ( timeout ) ;
65+ if ( this . retries < this . maxRetries ) {
6466 this . retries ++ ;
6567 // first retry 1sec, 2sec, 3sec total 6sec retry sequence
6668 // retry will only happen in case of deploying multi parse server instance
6769 // at the same time
6870 // modern systems like k8 avoid this by doing rolling updates
69- await new Promise ( resolve => setTimeout ( resolve , 1000 * this . retries ) ) ;
71+ await this . wait ( 1000 * this . retries ) ;
7072 await this . execute ( ) ;
7173 } else {
7274 logger . error ( e ) ;
@@ -75,6 +77,11 @@ export class DefinedSchemas {
7577 }
7678 }
7779
80+ // Required for testing purpose
81+ async wait ( time ) {
82+ await new Promise ( resolve => setTimeout ( resolve , time ) ) ;
83+ }
84+
7885 async enforceCLPForNonProvidedClass ( ) {
7986 const nonProvidedClasses = this . allCloudSchemas . filter (
8087 cloudSchema =>
0 commit comments