diff --git a/internal/client/storage.go b/internal/client/storage.go index c3820cd8..1548683a 100644 --- a/internal/client/storage.go +++ b/internal/client/storage.go @@ -15,7 +15,6 @@ import ( "github.com/AdguardTeam/AdGuardHome/internal/whois" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/hostsfile" - "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/logutil/slogutil" ) @@ -506,7 +505,7 @@ func (s *Storage) FindByMAC(mac net.HardwareAddr) (p *Persistent, ok bool) { // RemoveByName removes persistent client information. ok is false if no such // client exists by that name. -func (s *Storage) RemoveByName(name string) (ok bool) { +func (s *Storage) RemoveByName(ctx context.Context, name string) (ok bool) { s.mu.Lock() defer s.mu.Unlock() @@ -516,7 +515,7 @@ func (s *Storage) RemoveByName(name string) (ok bool) { } if err := p.CloseUpstreams(); err != nil { - log.Error("client storage: removing client %q: %s", p.Name, err) + s.logger.ErrorContext(ctx, "removing client", "name", p.Name, slogutil.KeyError, err) } s.index.remove(p) diff --git a/internal/client/storage_test.go b/internal/client/storage_test.go index a2101013..b87383d0 100644 --- a/internal/client/storage_test.go +++ b/internal/client/storage_test.go @@ -735,7 +735,7 @@ func TestStorage_RemoveByName(t *testing.T) { for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - tc.want(t, s.RemoveByName(tc.cliName)) + tc.want(t, s.RemoveByName(ctx, tc.cliName)) }) } @@ -744,8 +744,8 @@ func TestStorage_RemoveByName(t *testing.T) { err = s.Add(ctx, existingClient) require.NoError(t, err) - assert.True(t, s.RemoveByName(existingName)) - assert.False(t, s.RemoveByName(existingName)) + assert.True(t, s.RemoveByName(ctx, existingName)) + assert.False(t, s.RemoveByName(ctx, existingName)) }) } diff --git a/internal/home/clientshttp.go b/internal/home/clientshttp.go index 6d06ae00..8cea8650 100644 --- a/internal/home/clientshttp.go +++ b/internal/home/clientshttp.go @@ -369,7 +369,7 @@ func (clients *clientsContainer) handleDelClient(w http.ResponseWriter, r *http. return } - if !clients.storage.RemoveByName(cj.Name) { + if !clients.storage.RemoveByName(r.Context(), cj.Name) { aghhttp.Error(r, w, http.StatusBadRequest, "Client not found") return