@@ -11,6 +11,7 @@ import (
1111 "fmt"
1212 "html/template"
1313 "io/fs"
14+ "math"
1415 "net/http"
1516 "net/url"
1617 "os"
@@ -294,6 +295,8 @@ func (h *ContainerHandler) idleAppShutdown(ctx context.Context) {
294295}
295296
296297func (h * ContainerHandler ) healthChecker (ctx context.Context ) {
298+ time .Sleep (60 * time .Second ) // wait for 1 minute to let the app start up
299+ h .Debug ().Msgf ("Health checker started for app %s" , h .app .Id )
297300 for range h .healthCheckTicker .C {
298301 err := h .WaitForHealth (h .containerConfig .StatusHealthAttempts )
299302 if err == nil {
@@ -707,21 +710,18 @@ func (h *ContainerHandler) WaitForHealth(attempts int) error {
707710
708711 var err error
709712 var resp * http.Response
710- proxyUrl , err := url .Parse (h .GetProxyUrl ())
711- if err != nil {
712- return err
713- }
714- if ! h .stripAppPath {
715- // Apps like Streamlit require the app path to be present
716- proxyUrl = proxyUrl .JoinPath (h .app .Path )
717- }
713+ for attempt := 1 ; attempt <= attempts ; attempt ++ {
714+ proxyUrl , err := url .Parse (h .GetProxyUrl ())
715+ if err != nil {
716+ return err
717+ }
718+ if ! h .stripAppPath {
719+ // Apps like Streamlit require the app path to be present
720+ proxyUrl = proxyUrl .JoinPath (h .app .Path )
721+ }
718722
719- proxyUrl = proxyUrl .JoinPath (h .health )
720- if err != nil {
721- return err
722- }
723+ proxyUrl = proxyUrl .JoinPath (h .health )
723724
724- for attempt := 1 ; attempt <= attempts ; attempt ++ {
725725 resp , err = client .Get (proxyUrl .String ())
726726 statusCode := "N/A"
727727 if err == nil {
@@ -736,7 +736,8 @@ func (h *ContainerHandler) WaitForHealth(attempts int) error {
736736 }
737737
738738 h .Debug ().Msgf ("Attempt %d failed on %s : status %s err %s" , attempt , proxyUrl , statusCode , err )
739- time .Sleep (1 * time .Second )
739+ sleepSecs := math .Min (float64 (attempt ), 5 )
740+ time .Sleep (time .Duration (sleepSecs ) * time .Second )
740741 }
741742 return err
742743}
0 commit comments