From b5b466088d8858ab37493d1065aa60ae76d3c138 Mon Sep 17 00:00:00 2001 From: Christian Provenzano <18606244+caproven@users.noreply.github.com> Date: Wed, 11 May 2022 20:41:10 -0400 Subject: [PATCH] server: Move director interrupt handler to method --- server/proxy/httpproxy/director.go | 13 ++++++++++--- server/proxy/httpproxy/director_test.go | 7 +------ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/server/proxy/httpproxy/director.go b/server/proxy/httpproxy/director.go index add97621d..6862e2a69 100644 --- a/server/proxy/httpproxy/director.go +++ b/server/proxy/httpproxy/director.go @@ -45,9 +45,7 @@ func newDirector(lg *zap.Logger, urlsFunc GetProxyURLs, failureWait time.Duratio stopc: make(chan struct{}), donec: make(chan struct{}), } - osutil.RegisterInterruptHandler(func() { - close(d.stopc) - }) + osutil.RegisterInterruptHandler(d.stop) d.refresh() go func() { defer close(d.donec) @@ -129,6 +127,15 @@ func (d *director) endpoints() []*endpoint { return filtered } +func (d *director) stop() { + close(d.stopc) + select { + case <-d.donec: + case <-time.After(time.Second): + d.lg.Warn("timed out waiting for director to stop") + } +} + func newEndpoint(lg *zap.Logger, u url.URL, failureWait time.Duration) *endpoint { ep := endpoint{ lg: lg, diff --git a/server/proxy/httpproxy/director_test.go b/server/proxy/httpproxy/director_test.go index 6f831d1aa..7c6716fe3 100644 --- a/server/proxy/httpproxy/director_test.go +++ b/server/proxy/httpproxy/director_test.go @@ -67,12 +67,7 @@ func TestNewDirectorScheme(t *testing.T) { t.Errorf("#%d: want endpoints = %#v, got = %#v", i, tt.want, gep) } - close(got.stopc) - select { - case <-got.donec: - case <-time.After(time.Second): - t.Fatalf("done took too long") - } + got.stop() } }