diff --git a/.gitignore b/.gitignore index c2e8386f..ae506d97 100755 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ todo.md .*.swp .aider* +mtrace.json diff --git a/Dockerfile b/Dockerfile index c74aa6c6..8b837f65 100644 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ RUN --mount=type=cache,target="/go/pkg/mod" \ --mount=type=bind,src=pkg,dst=/src/pkg \ make build && \ mkdir -p /app/error_pages /app/certs && \ - cp bin/go-proxy /app/go-proxy + mv bin/go-proxy /app/go-proxy # Stage 2: Final image FROM scratch diff --git a/internal/docker/idlewatcher/round_trip.go b/internal/docker/idlewatcher/round_trip.go index 738bfc62..72363ccf 100644 --- a/internal/docker/idlewatcher/round_trip.go +++ b/internal/docker/idlewatcher/round_trip.go @@ -17,12 +17,6 @@ func (rt roundTripper) RoundTrip(req *http.Request) (*http.Response, error) { } func (w *watcher) roundTrip(origRoundTrip roundTripFunc, req *http.Request) (*http.Response, error) { - // wake the container - select { - case w.wakeCh <- struct{}{}: - default: - } - // target site is ready, passthrough if w.ready.Load() { return origRoundTrip(req) @@ -53,6 +47,11 @@ func (w *watcher) roundTrip(origRoundTrip roundTripFunc, req *http.Request) (*ht case <-w.ctx.Done(): return default: + // wake the container and reset idle timer + select { + case w.wakeCh <- struct{}{}: + default: + } resp, err := origRoundTrip(req) if err == nil { w.ready.Store(true) @@ -75,9 +74,9 @@ func (w *watcher) roundTrip(origRoundTrip roundTripFunc, req *http.Request) (*ht if ctx.Err() == context.DeadlineExceeded { return w.makeErrResp("Timed out waiting for %s to fully wake", w.ContainerName) } - return w.makeErrResp("idlewatcher has stopped\n%s", w.ctx.Err().Error()) + return w.makeErrResp("idlewatcher has stopped\n%s", w.ctx.Err()) case <-w.ctx.Done(): - return w.makeErrResp("idlewatcher has stopped\n%s", w.ctx.Err().Error()) + return w.makeErrResp("idlewatcher has stopped\n%s", w.ctx.Err()) } } } diff --git a/internal/docker/idlewatcher/watcher.go b/internal/docker/idlewatcher/watcher.go index bb541667..6b4c1d4d 100644 --- a/internal/docker/idlewatcher/watcher.go +++ b/internal/docker/idlewatcher/watcher.go @@ -170,6 +170,10 @@ func (w *watcher) containerStatus() (string, E.NestedError) { } func (w *watcher) wakeIfStopped() E.NestedError { + if w.ready.Load() || w.ContainerRunning { + return nil + } + status, err := w.containerStatus() if err.HasError() { @@ -249,9 +253,11 @@ func (w *watcher) watchUntilCancel() { switch { // create / start / unpause case e.Action.IsContainerWake(): + w.ContainerRunning = true ticker.Reset(w.IdleTimeout) w.l.Info(e) default: // stop / pause / kill + w.ContainerRunning = false ticker.Stop() w.ready.Store(false) w.l.Info(e) diff --git a/internal/route/http.go b/internal/route/http.go index 7d99919f..3be73362 100755 --- a/internal/route/http.go +++ b/internal/route/http.go @@ -135,8 +135,8 @@ func (r *HTTPRoute) Start() E.NestedError { } } - if r.entry.URL.Port() == "0" || - r.entry.IsDocker() && !r.entry.ContainerRunning { + if !r.entry.UseIdleWatcher() && (r.entry.URL.Port() == "0" || + r.entry.IsDocker() && !r.entry.ContainerRunning) { // TODO: if it use idlewatcher, set mux to dummy mux return nil } diff --git a/screenshots/webui.png b/screenshots/webui.png index ca3d7715..a67ff9d7 100644 Binary files a/screenshots/webui.png and b/screenshots/webui.png differ