From b9ee5d6348e696ff0b44dabee601469c545c8bd9 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Wed, 19 Oct 2022 14:20:15 +0300 Subject: [PATCH] all: close upstreams more --- internal/dnsforward/http.go | 1 + internal/home/clients.go | 11 +++++++---- internal/home/clientshttp.go | 1 + 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/internal/dnsforward/http.go b/internal/dnsforward/http.go index 91e31b70a75..97749c9cb06 100644 --- a/internal/dnsforward/http.go +++ b/internal/dnsforward/http.go @@ -603,6 +603,7 @@ func checkDNS( if err != nil { return fmt.Errorf("failed to choose upstream for %q: %w", upstreamAddr, err) } + defer func() { err = errors.WithDeferred(err, u.Close()) }() if err = healthCheck(u); err != nil { err = fmt.Errorf("upstream %q fails to exchange: %w", upstreamAddr, err) diff --git a/internal/home/clients.go b/internal/home/clients.go index 2c45e19995d..b505bf5fd4d 100644 --- a/internal/home/clients.go +++ b/internal/home/clients.go @@ -727,7 +727,7 @@ func (clients *clientsContainer) Update(name string, c *Client) (err error) { } } - // update ID index + // Update ID index. for _, id := range prev.IDs { delete(clients.idIndex, id) } @@ -736,14 +736,17 @@ func (clients *clientsContainer) Update(name string, c *Client) (err error) { } } - // update Name index + // Update name index. if prev.Name != c.Name { delete(clients.list, prev.Name) clients.list[c.Name] = prev } - // update upstreams cache - c.upstreamConfig = nil + // Update upstreams cache. + err = c.closeUpstreams() + if err != nil { + return err + } *prev = *c diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 59821d0aae2..4e4d22f22bc 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -179,6 +179,7 @@ func (clients *clientsContainer) handleDelClient(w http.ResponseWriter, r *http. if !clients.Del(cj.Name) { aghhttp.Error(r, w, http.StatusBadRequest, "Client not found") + return }