@@ -248,8 +248,11 @@ func dedupVolumes(volumes []string) []string {
248248
249249func (h * ContainerHandler ) idleAppShutdown (ctx context.Context ) {
250250 for range h .idleShutdownTicker .C {
251+ if h .currentState != ContainerStateRunning {
252+ continue
253+ }
251254 idleTimeSecs := time .Now ().Unix () - h .app .lastRequestTime .Load ()
252- if h . currentState != ContainerStateRunning || idleTimeSecs < int64 (h .containerConfig .IdleShutdownSecs ) {
255+ if idleTimeSecs < int64 (h .containerConfig .IdleShutdownSecs ) {
253256 // Not idle
254257 h .Trace ().Msgf ("App %s not idle, last request %d seconds ago" , h .app .Id , idleTimeSecs )
255258 continue
@@ -711,17 +714,22 @@ func (h *ContainerHandler) WaitForHealth(attempts int) error {
711714 var err error
712715 var resp * http.Response
713716 for attempt := 1 ; attempt <= attempts ; attempt ++ {
714- proxyUrl , err := url .Parse (h .GetProxyUrl ())
715- if err != nil {
716- return err
717+ var proxyUrl * url.URL
718+ proxyUrl , err = url .Parse (h .GetProxyUrl ())
719+ if err != nil || proxyUrl .Host == "" {
720+ if err == nil {
721+ err = fmt .Errorf ("could not find container proxy url" )
722+ }
723+ sleepSecs := math .Min (float64 (attempt ), 5 )
724+ time .Sleep (time .Duration (sleepSecs ) * time .Second )
725+ continue
717726 }
718727 if ! h .stripAppPath {
719728 // Apps like Streamlit require the app path to be present
720729 proxyUrl = proxyUrl .JoinPath (h .app .Path )
721730 }
722731
723732 proxyUrl = proxyUrl .JoinPath (h .health )
724-
725733 resp , err = client .Get (proxyUrl .String ())
726734 statusCode := "N/A"
727735 if err == nil {
@@ -739,6 +747,8 @@ func (h *ContainerHandler) WaitForHealth(attempts int) error {
739747 sleepSecs := math .Min (float64 (attempt ), 5 )
740748 time .Sleep (time .Duration (sleepSecs ) * time .Second )
741749 }
750+
751+ h .Error ().Msgf ("Health check failed for app %s after %d attempts: %v" , h .app .Id , attempts , err )
742752 return err
743753}
744754
0 commit comments