diff --git a/internal/client/addrproc.go b/internal/client/addrproc.go index 7afbd4a4..abd2ed69 100644 --- a/internal/client/addrproc.go +++ b/internal/client/addrproc.go @@ -236,7 +236,7 @@ func (p *DefaultAddrProc) Process(ctx context.Context, ip netip.Addr) { // to be used as a goroutine. Once clientIPs is closed, process exits. func (p *DefaultAddrProc) process(ctx context.Context, catchPanics bool) { if catchPanics { - slogutil.RecoverAndLog(ctx, p.logger) + defer slogutil.RecoverAndLog(ctx, p.logger) } p.logger.InfoContext(ctx, "processing addresses") diff --git a/internal/client/storage_test.go b/internal/client/storage_test.go index 7374101d..ed634444 100644 --- a/internal/client/storage_test.go +++ b/internal/client/storage_test.go @@ -21,6 +21,17 @@ import ( "github.com/stretchr/testify/require" ) +// testStorage is a helper function that returns initialized storage. +func testStorage(tb testing.TB) (s *client.Storage) { + ctx := testutil.ContextWithTimeout(tb, testTimeout) + s, err := client.NewStorage(ctx, &client.StorageConfig{ + Logger: slogutil.NewDiscardLogger(), + }) + require.NoError(tb, err) + + return s +} + // testHostsContainer is a mock implementation of the [client.HostsContainer] // interface. type testHostsContainer struct { @@ -571,11 +582,7 @@ func TestStorage_Add(t *testing.T) { } ctx := testutil.ContextWithTimeout(t, testTimeout) - s, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - }) - require.NoError(t, err) - + s := testStorage(t) tags := s.AllowedTags() require.NotZero(t, len(tags)) require.True(t, slices.IsSorted(tags)) @@ -586,7 +593,7 @@ func TestStorage_Add(t *testing.T) { _, ok = slices.BinarySearch(tags, notAllowedTag) require.False(t, ok) - err = s.Add(ctx, existingClient) + err := s.Add(ctx, existingClient) require.NoError(t, err) testCases := []struct { @@ -706,12 +713,8 @@ func TestStorage_RemoveByName(t *testing.T) { } ctx := testutil.ContextWithTimeout(t, testTimeout) - s, err := client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - }) - require.NoError(t, err) - - err = s.Add(ctx, existingClient) + s := testStorage(t) + err := s.Add(ctx, existingClient) require.NoError(t, err) testCases := []struct { @@ -735,11 +738,7 @@ func TestStorage_RemoveByName(t *testing.T) { } t.Run("duplicate_remove", func(t *testing.T) { - s, err = client.NewStorage(ctx, &client.StorageConfig{ - Logger: slogutil.NewDiscardLogger(), - }) - require.NoError(t, err) - + s = testStorage(t) err = s.Add(ctx, existingClient) require.NoError(t, err) diff --git a/internal/home/home.go b/internal/home/home.go index 9e3e5fb7..b986e972 100644 --- a/internal/home/home.go +++ b/internal/home/home.go @@ -115,10 +115,10 @@ func Main(clientBuildFS fs.FS) { signal.Notify(signals, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT) go func() { + ctx := context.Background() for { sig := <-signals log.Info("Received signal %q", sig) - ctx := context.Background() switch sig { case syscall.SIGHUP: Context.clients.storage.ReloadARP(ctx)