@@ -69,27 +69,46 @@ function isWorker() {
6969}
7070
7171/**
72- * Check master endpoint health
72+ * Check master endpoint health, retrying up to 3 times.
7373 */
74- async function checkMasterHealth ( masterEndpoint : string ) {
75- try {
76- const response = await fetch ( `${ masterEndpoint } /health` , {
77- method : 'GET' ,
78- signal : AbortSignal . timeout ( 10000 ) // 10 second timeout
79- } ) ;
80-
81- if ( ! response . ok ) {
82- throw new Error ( `Health check returned status ${ response . status } ` ) ;
74+ async function checkMasterHealth ( masterEndpoint : string ) {
75+ const MAX_RETRIES = 3 ;
76+ let retryCount = 0 ;
77+ while ( retryCount < MAX_RETRIES ) {
78+ retryCount ++ ;
79+ try {
80+ const response = await fetch ( `${ masterEndpoint } /health` , {
81+ method : 'GET' ,
82+ signal : AbortSignal . timeout ( 10000 ) // 10 second timeout
83+ } ) ;
84+
85+ if ( ! response . ok ) {
86+ throw new Error ( `Health check returned status ${ response . status } ` ) ;
87+ }
88+ if ( retryCount > 1 ) {
89+ console . debug ( `[K8s] Successfully reached master after retry (attempt ${ retryCount } /${ MAX_RETRIES } ): ${ masterEndpoint } ` ) ;
90+ }
91+ return true ;
92+ } catch ( error : any ) {
93+ console . error ( error ) ;
94+ console . debug ( `[K8s] Health check error (attempt ${ retryCount } /${ MAX_RETRIES } ): ${ error instanceof Error ? error . message : error } - ${ masterEndpoint } ` ) ;
95+ if ( retryCount < MAX_RETRIES ) {
96+ // Wait briefly before retrying
97+ await sleep ( 3 ) ;
98+ continue ;
99+ }
83100 }
84- return true ;
85- } catch ( error : any ) {
86- console . error ( `[K8s] Cannot reach master at ${ masterEndpoint } ` ) ;
87- console . error ( `[K8s] Error: ${ error . message } ` ) ;
101+ }
102+
103+ console . error ( `[K8s] Failed to reach master after ${ MAX_RETRIES } attempts: ${ masterEndpoint } ` ) ;
104+ if ( ! ApiConfig . isMasterNode ( ) ) {
105+ // If not master node, exit the process
88106 process . exit ( 1 ) ;
89- return false ;
90107 }
108+ return false ;
91109}
92110
111+
93112function addCorsHeaders ( reply : any ) {
94113 reply . header ( "Access-Control-Allow-Origin" , "*" ) ;
95114 reply . header (
@@ -413,7 +432,11 @@ export function buildApp(
413432 routeAliases : any ,
414433 enable_cache : boolean
415434) : FastifyInstance {
416- const app = fastify ( { logger : true } ) ;
435+ const app = fastify ( {
436+ logger : true ,
437+ // TODO: change appropriately as needed
438+ bodyLimit : 500 * 1024 * 1024 // 500MB
439+ } ) ;
417440
418441 // Add CORS handling
419442 app . addHook ( "onRequest" , ( request , reply , done ) => {
0 commit comments