From 4a89642f7f208c712c57b5c70e3ed8d7472daf8c Mon Sep 17 00:00:00 2001 From: Maisem Ali Date: Thu, 23 Mar 2023 18:54:22 -0700 Subject: [PATCH] log/sockstatlog: make shutdown close idle connections Updates tailscale/corp#10030 Signed-off-by: Maisem Ali --- log/sockstatlog/logger.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/log/sockstatlog/logger.go b/log/sockstatlog/logger.go index 4ac84c154..e2303a19c 100644 --- a/log/sockstatlog/logger.go +++ b/log/sockstatlog/logger.go @@ -36,6 +36,8 @@ type Logger struct { logf logger.Logf logger *logtail.Logger + filch *filch.Filch + tr *http.Transport } // deltaStat represents the bytes transferred during a time period. @@ -88,6 +90,8 @@ func NewLogger(logdir string, logf logger.Logf, logID logid.PublicID) (*Logger, cancelFn: cancel, ticker: time.NewTicker(pollPeriod), logf: logf, + filch: filch, + tr: logpolicy.NewLogtailTransport(logtail.DefaultHost), } logger.logger = logtail.NewLogger(logtail.Config{ BaseURL: logpolicy.LogURL(), @@ -107,7 +111,7 @@ func NewLogger(logdir string, logf logger.Logf, logID logid.PublicID) (*Logger, }, Stderr: io.Discard, // don't log to stderr - HTTPC: &http.Client{Transport: logpolicy.NewLogtailTransport(logtail.DefaultHost)}, + HTTPC: &http.Client{Transport: logger.tr}, }, logf) go logger.poll() @@ -166,8 +170,10 @@ func (l *Logger) Flush() { func (l *Logger) Shutdown() { l.ticker.Stop() - l.logger.Shutdown(context.Background()) + l.logger.Shutdown(l.ctx) l.cancelFn() + l.filch.Close() + l.tr.CloseIdleConnections() } // delta calculates the delta stats between two SockStats snapshots.