refactor: clean up code and fix race condition in idlewatcher

This commit is contained in:
yusing
2025-03-28 08:10:03 +08:00
parent 95fe294f7d
commit a7da8ffb90
8 changed files with 264 additions and 196 deletions

View File

@@ -8,7 +8,6 @@ import (
"time"
"github.com/yusing/go-proxy/internal/net/types"
"github.com/yusing/go-proxy/internal/watcher/health"
)
// Setup implements types.Stream.
@@ -50,7 +49,7 @@ func (w *Watcher) wakeFromStream() error {
w.resetIdleTimer()
// pass through if container is already ready
if w.ready.Load() {
if w.ready() {
return nil
}
@@ -78,7 +77,9 @@ func (w *Watcher) wakeFromStream() error {
default:
}
if w.Status() == health.StatusHealthy {
if ready, err := w.checkUpdateState(); err != nil {
return err
} else if ready {
w.resetIdleTimer()
w.Debug().Msg("container is ready, passing through to " + w.hc.URL().String())
return nil