mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
fixed idlewatcher panics and incorrect behavior, update screenshot
This commit is contained in:
parent
03cad9f315
commit
de7805f281
6 changed files with 17 additions and 11 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -19,3 +19,4 @@ todo.md
|
|||
|
||||
.*.swp
|
||||
.aider*
|
||||
mtrace.json
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 183 KiB After Width: | Height: | Size: 286 KiB |
Loading…
Add table
Reference in a new issue