From dff8941bd3fe9686885d397948138199694f56b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Fri, 28 Jun 2024 18:37:02 +0200 Subject: [PATCH] =?UTF-8?q?v0.0.476=20=C3=83properly=20close=20cursor=20in?= =?UTF-8?q?=20wmo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 +++--- go.sum | 6 ++++++ goextVersion.go | 4 ++-- wmo/queryAggregate.go | 6 ++++++ wmo/queryFind.go | 2 ++ wmo/queryFindOne.go | 2 ++ wmo/queryList.go | 4 ++++ 7 files changed, 25 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 06e3014..0a280e2 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/jmoiron/sqlx v1.4.0 github.com/rs/xid v1.5.0 github.com/rs/zerolog v1.33.0 - go.mongodb.org/mongo-driver v1.15.1 + go.mongodb.org/mongo-driver v1.16.0 golang.org/x/crypto v0.24.0 golang.org/x/sys v0.21.0 golang.org/x/term v0.21.0 @@ -21,7 +21,7 @@ require ( ) require ( - github.com/bytedance/sonic v1.11.8 // indirect + github.com/bytedance/sonic v1.11.9 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect github.com/chenzhuoyu/iasm v0.9.1 // indirect @@ -54,7 +54,7 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect golang.org/x/arch v0.8.0 // indirect - golang.org/x/image v0.17.0 // indirect + golang.org/x/image v0.18.0 // indirect golang.org/x/net v0.26.0 // indirect golang.org/x/text v0.16.0 // indirect google.golang.org/protobuf v1.34.2 // indirect diff --git a/go.sum b/go.sum index 0c5b3a5..513d4a5 100644 --- a/go.sum +++ b/go.sum @@ -22,6 +22,8 @@ github.com/bytedance/sonic v1.11.7 h1:k/l9p1hZpNIMJSk37wL9ltkcpqLfIho1vYthi4xT2t github.com/bytedance/sonic v1.11.7/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic v1.11.8 h1:Zw/j1KfiS+OYTi9lyB3bb0CFxPJVkM17k1wyDG32LRA= github.com/bytedance/sonic v1.11.8/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= +github.com/bytedance/sonic v1.11.9 h1:LFHENlIY/SLzDWverzdOvgMztTxcfcF+cqNsz9pK5zg= +github.com/bytedance/sonic v1.11.9/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.0/go.mod h1:UmRT+IRTGKz/DAkzcEGzyVqQFJ7H9BqwBO3pm9H/+HY= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -220,6 +222,8 @@ go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUS go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.mongodb.org/mongo-driver v1.15.1 h1:l+RvoUOoMXFmADTLfYDm7On9dRm7p4T80/lEQM+r7HU= go.mongodb.org/mongo-driver v1.15.1/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.16.0 h1:tpRsfBJMROVHKpdGyc1BBEzzjDUWjItxbVSZ8Ls4BQ4= +go.mongodb.org/mongo-driver v1.16.0/go.mod h1:oB6AhJQvFQL4LEHyXi6aJzQJtBiTQHiAd83l0GdFaiw= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.7.0 h1:pskyeJh/3AmoQ8CPE95vxHLqp1G1GfGNXTmcl9NEKTc= golang.org/x/arch v0.7.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= @@ -252,6 +256,8 @@ golang.org/x/image v0.16.0 h1:9kloLAKhUufZhA12l5fwnx2NZW39/we1UhBesW433jw= golang.org/x/image v0.16.0/go.mod h1:ugSZItdV4nOxyqp56HmXwH0Ry0nBCpjnZdpDaIHdoPs= golang.org/x/image v0.17.0 h1:nTRVVdajgB8zCMZVsViyzhnMKPwYeroEERRC64JuLco= golang.org/x/image v0.17.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= +golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= +golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= diff --git a/goextVersion.go b/goextVersion.go index bb1923e..c1acb57 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.475" +const GoextVersion = "0.0.476" -const GoextVersionTimestamp = "2024-06-16T17:14:21+0200" +const GoextVersionTimestamp = "2024-06-28T18:37:02+0200" diff --git a/wmo/queryAggregate.go b/wmo/queryAggregate.go index 6dc0ab7..2c8e2c1 100644 --- a/wmo/queryAggregate.go +++ b/wmo/queryAggregate.go @@ -19,6 +19,8 @@ func (c *Coll[TData]) Aggregate(ctx context.Context, pipeline mongo.Pipeline, op return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + res, err := c.decodeAll(ctx, cursor) if err != nil { return nil, exerr.Wrap(err, "failed to decode values").Build() @@ -38,6 +40,8 @@ func (c *Coll[TData]) AggregateOneOpt(ctx context.Context, pipeline mongo.Pipeli return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + if cursor.Next(ctx) { v, err := c.decodeSingle(ctx, cursor) if err != nil { @@ -60,6 +64,8 @@ func (c *Coll[TData]) AggregateOne(ctx context.Context, pipeline mongo.Pipeline, return *new(TData), exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Any("options", opts).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + if cursor.Next(ctx) { v, err := c.decodeSingle(ctx, cursor) if err != nil { diff --git a/wmo/queryFind.go b/wmo/queryFind.go index 3b71d2e..076685e 100644 --- a/wmo/queryFind.go +++ b/wmo/queryFind.go @@ -64,6 +64,8 @@ func (c *Coll[TData]) Find(ctx context.Context, filter bson.M, opts ...*options. return nil, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + res, err := c.decodeAll(ctx, cursor) if err != nil { return nil, exerr.Wrap(err, "failed to decode values").Build() diff --git a/wmo/queryFindOne.go b/wmo/queryFindOne.go index 53e00ca..8bc4681 100644 --- a/wmo/queryFindOne.go +++ b/wmo/queryFindOne.go @@ -80,6 +80,8 @@ func (c *Coll[TData]) findOneInternal(ctx context.Context, filter bson.M, allowN return nil, exerr.Wrap(err, "mongo-aggregation [find-one] failed").Any("pipeline", pipeline).Str("collection", c.Name()).NoLog().Build() } + defer func() { _ = cursor.Close(ctx) }() + if cursor.Next(ctx) { v, err := c.decodeSingle(ctx, cursor) if err != nil { diff --git a/wmo/queryList.go b/wmo/queryList.go index b0c81e9..37d0214 100644 --- a/wmo/queryList.go +++ b/wmo/queryList.go @@ -69,6 +69,8 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int, return nil, ct.CursorToken{}, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + // fast branch if pageSize == nil { entries, err := c.decodeAll(ctx, cursor) @@ -118,6 +120,8 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.RawFilter) (int64, er return 0, exerr.Wrap(err, "mongo-aggregation failed").Any("pipeline", pipeline).Str("collection", c.Name()).Build() } + defer func() { _ = cursor.Close(ctx) }() + if cursor.Next(ctx) { v := countRes{} err = cursor.Decode(&v)