diff --git a/internal/idlewatcher/handle_http.go b/internal/idlewatcher/handle_http.go index 84f4ba55..e43bd9a7 100644 --- a/internal/idlewatcher/handle_http.go +++ b/internal/idlewatcher/handle_http.go @@ -176,7 +176,14 @@ func (w *Watcher) wakeFromHTTP(rw http.ResponseWriter, r *http.Request) (shouldN } if !acceptHTML { - serveStaticContent(rw, http.StatusOK, "text/plain", []byte("Container woken")) + // send a continue response to prevent client wait-header timeout + rw.WriteHeader(http.StatusContinue) + ready := w.waitForReady(r.Context()) + if !ready { + serveStaticContent(rw, http.StatusInternalServerError, "text/plain", []byte("Timeout waiting for container to become ready")) + } else { + http.Redirect(rw, r, r.URL.Path, http.StatusSeeOther) + } return false } diff --git a/internal/idlewatcher/state.go b/internal/idlewatcher/state.go index 2aa06dcc..46aee9a2 100644 --- a/internal/idlewatcher/state.go +++ b/internal/idlewatcher/state.go @@ -75,7 +75,7 @@ func (w *Watcher) waitForReady(ctx context.Context) bool { // Wait for ready notification or context cancellation select { case <-w.readyNotifyCh: - return w.ready() // double-check in case of race condition + return true case <-ctx.Done(): return false } diff --git a/internal/idlewatcher/watcher.go b/internal/idlewatcher/watcher.go index d042da61..90a5030b 100644 --- a/internal/idlewatcher/watcher.go +++ b/internal/idlewatcher/watcher.go @@ -332,6 +332,7 @@ func NewWatcher(parent task.Parent, r types.Route, cfg *types.IdlewatcherConfig) w.idleTicker.Stop() w.healthTicker.Stop() + w.setReady() close(w.readyNotifyCh) w.task.Finish(cause) }()