From 974735d415fe249eb670c31bf0b6a5fcfeed4c59 Mon Sep 17 00:00:00 2001 From: James Houlahan Date: Fri, 21 Oct 2022 12:00:35 +0200 Subject: [PATCH] Other: Bump liteapi version to fix goroutine leaks --- go.mod | 2 +- go.sum | 4 ++-- internal/user/user.go | 4 +--- internal/user/user_test.go | 2 +- tests/ctx_helper_test.go | 9 ++++++--- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 69da1ffb..b10994bc 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/sirupsen/logrus v1.9.0 github.com/stretchr/testify v1.8.0 github.com/urfave/cli/v2 v2.16.3 - gitlab.protontech.ch/go/liteapi v1.0.0 + gitlab.protontech.ch/go/liteapi v0.35.0 golang.org/x/exp v0.0.0-20220921164117-439092de6870 golang.org/x/net v0.1.0 golang.org/x/sys v0.1.0 diff --git a/go.sum b/go.sum index 40e2f697..06c5ec17 100644 --- a/go.sum +++ b/go.sum @@ -399,8 +399,8 @@ github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsr github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= github.com/zclconf/go-cty v1.11.0 h1:726SxLdi2SDnjY+BStqB9J1hNp4+2WlzyXLuimibIe0= github.com/zclconf/go-cty v1.11.0/go.mod h1:s9IfD1LK5ccNMSWCVFCE2rJfHiZgi7JijgeWIMfhLvA= -gitlab.protontech.ch/go/liteapi v1.0.0 h1:MGds9QjSrEUxRRAwqJ4dxXoBosSNM1+NOUmlP6h1eko= -gitlab.protontech.ch/go/liteapi v1.0.0/go.mod h1:VCEA83UCi9f3XCP9W/XUIFnJKwokGB46lKUHBNzPWsQ= +gitlab.protontech.ch/go/liteapi v0.35.0 h1:26Yx8+pp14MPxV1DL8gU+cahPigrEATzm3WpoNQs7kU= +gitlab.protontech.ch/go/liteapi v0.35.0/go.mod h1:NuLWhVn8c0bR9qUaJER7VbPFu7oEowWWcP5ANgQHwRo= go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU= go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU= go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8= diff --git a/internal/user/user.go b/internal/user/user.go index 9882a9cf..3a59b762 100644 --- a/internal/user/user.go +++ b/internal/user/user.go @@ -373,9 +373,7 @@ func (user *User) Close() error { user.waitSync() // Close the user's API client. - if err := user.client.Close(); err != nil { - logrus.WithError(err).Error("Failed to close API client") - } + user.client.Close() // Close the user's update channels. user.updateCh.Values(func(updateCh []*queue.QueuedChannel[imap.Update]) { diff --git a/internal/user/user_test.go b/internal/user/user_test.go index 0fbdf67c..9ec9c548 100644 --- a/internal/user/user_test.go +++ b/internal/user/user_test.go @@ -126,7 +126,7 @@ func withAccount(tb testing.TB, s *server.Server, username, password string, ema func withUser(tb testing.TB, ctx context.Context, _ *server.Server, m *liteapi.Manager, username, password string, fn func(*User)) { //nolint:unparam,revive client, apiAuth, err := m.NewClientWithLogin(ctx, username, []byte(password)) require.NoError(tb, err) - defer func() { require.NoError(tb, client.Close()) }() + defer client.Close() apiUser, err := client.GetUser(ctx) require.NoError(tb, err) diff --git a/tests/ctx_helper_test.go b/tests/ctx_helper_test.go index ba4349df..ba263578 100644 --- a/tests/ctx_helper_test.go +++ b/tests/ctx_helper_test.go @@ -19,6 +19,7 @@ package tests import ( "context" + "fmt" "runtime" "github.com/bradenaw/juniper/stream" @@ -34,15 +35,17 @@ func (t *testCtx) withClient(ctx context.Context, username string, fn func(conte return err } + defer c.Close() + if err := fn(ctx, c); err != nil { - return err + return fmt.Errorf("failed to execute with client: %w", err) } if err := c.AuthDelete(ctx); err != nil { - return err + return fmt.Errorf("failed to delete auth: %w", err) } - return c.Close() + return nil } func (t *testCtx) createMessages(ctx context.Context, username, addrID string, req []liteapi.ImportReq) error {