Skip to content

Commit

Permalink
all: close upstreams more
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Oct 19, 2022
1 parent eaca476 commit b9ee5d6
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions internal/dnsforward/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions internal/home/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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

Expand Down
1 change: 1 addition & 0 deletions internal/home/clientshttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit b9ee5d6

Please sign in to comment.