Skip to content

Commit a0d5226

Browse files
committed
Fix container health check
1 parent 1907fd8 commit a0d5226

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

internal/app/container_handler.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -248,8 +248,11 @@ func dedupVolumes(volumes []string) []string {
248248

249249
func (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

Comments
 (0)