mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-21 16:01:22 +02:00
fix(idlewatcher): improve container readiness handling in wakeFromHTTP
- Updated the wakeFromHTTP method to send a 100 Continue response to prevent client wait-header timeout. - Implemented logic for non-HTML requests to wait for the container to become ready, returning an error message if it times out, or redirecting if successful. - Adjusted the waitForReady method to return true upon receiving a ready notification.
This commit is contained in:
@@ -176,7 +176,14 @@ func (w *Watcher) wakeFromHTTP(rw http.ResponseWriter, r *http.Request) (shouldN
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !acceptHTML {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ func (w *Watcher) waitForReady(ctx context.Context) bool {
|
|||||||
// Wait for ready notification or context cancellation
|
// Wait for ready notification or context cancellation
|
||||||
select {
|
select {
|
||||||
case <-w.readyNotifyCh:
|
case <-w.readyNotifyCh:
|
||||||
return w.ready() // double-check in case of race condition
|
return true
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -332,6 +332,7 @@ func NewWatcher(parent task.Parent, r types.Route, cfg *types.IdlewatcherConfig)
|
|||||||
|
|
||||||
w.idleTicker.Stop()
|
w.idleTicker.Stop()
|
||||||
w.healthTicker.Stop()
|
w.healthTicker.Stop()
|
||||||
|
w.setReady()
|
||||||
close(w.readyNotifyCh)
|
close(w.readyNotifyCh)
|
||||||
w.task.Finish(cause)
|
w.task.Finish(cause)
|
||||||
}()
|
}()
|
||||||
|
|||||||
Reference in New Issue
Block a user