From b30096f1fec256ec0f937b38735b5c91df8fe4db Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Tue, 12 Nov 2024 10:49:24 -0800 Subject: [PATCH 1/4] GODRIVER-3340 Add a test for goroutine leaks. (#1874) (cherry picked from commit c3448e685952c728a60ac002bd8c3df36c8b899b) --- .evergreen/config.yml | 41 ++++++++++ etc/run-goleak-test.sh | 10 +++ internal/test/goleak/go.mod | 33 ++++++++ internal/test/goleak/go.sum | 74 +++++++++++++++++ internal/test/goleak/goleak_test.go | 122 ++++++++++++++++++++++++++++ 5 files changed, 280 insertions(+) create mode 100755 etc/run-goleak-test.sh create mode 100644 internal/test/goleak/go.mod create mode 100644 internal/test/goleak/go.sum create mode 100644 internal/test/goleak/goleak_test.go diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 90da768350..91b9ddd23f 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -388,6 +388,17 @@ functions: TASKFILE_TARGET: test-short args: [*task-runner, run-docker] + run-goleak-test: + - command: shell.exec + type: test + params: + shell: "bash" + working_dir: src/go.mongodb.org/mongo-driver + include_expansions_in_env: ["MONGODB_URI"] + script: | + ${PREPARE_SHELL} + bash etc/run-goleak-test.sh + run-ocsp-server: - command: subprocess.exec params: @@ -1100,6 +1111,26 @@ tasks: - func: bootstrap-mongo-orchestration - func: run-docker-test + - name: test-goroutine-leaks-replicaset + tags: ["goleak"] + commands: + - func: bootstrap-mongo-orchestration + vars: + TOPOLOGY: "replica_set" + AUTH: "noauth" + SSL: "nossl" + - func: run-goleak-test + + - name: test-goroutine-leaks-sharded + tags: ["goleak"] + commands: + - func: bootstrap-mongo-orchestration + vars: + TOPOLOGY: "sharded_cluster" + AUTH: "noauth" + SSL: "nossl" + - func: run-goleak-test + - name: test-load-balancer-noauth-nossl tags: ["load-balancer"] commands: @@ -2056,6 +2087,16 @@ buildvariants: tasks: - name: "test-docker-runner" + - name: goroutine-leaks-test + tags: ["pullrequest"] + display_name: "Goroutine Leaks Test" + run_on: + - ubuntu2204-large + expansions: + GO_DIST: "/opt/golang/go1.22" + tasks: + - name: ".goleak" + - matrix_name: "tests-rhel-36-with-zlib-support" tags: ["pullrequest"] matrix_spec: { version: ["3.6"], os-ssl-32: ["rhel87-64"] } diff --git a/etc/run-goleak-test.sh b/etc/run-goleak-test.sh new file mode 100755 index 0000000000..143df5e7f4 --- /dev/null +++ b/etc/run-goleak-test.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +# run-goleak-test +# Run goroutine leak tests. +set -eu +set +x + +echo "Running internal/test/goleak" +pushd internal/test/goleak +go test -v ./... >> ../../../test.suite +popd diff --git a/internal/test/goleak/go.mod b/internal/test/goleak/go.mod new file mode 100644 index 0000000000..8afebe5b6d --- /dev/null +++ b/internal/test/goleak/go.mod @@ -0,0 +1,33 @@ +module go.mongodb.go/mongo-driver/internal/test/goleak + +go 1.22 + +replace go.mongodb.org/mongo-driver => ../../../ + +// Note that the Go driver version is replaced with the local Go driver code +// by the replace directive above. +require go.mongodb.org/mongo-driver v1.13.1 + +require ( + github.com/stretchr/testify v1.9.0 + go.uber.org/goleak v1.3.0 +) + +require ( + github.com/davecgh/go-spew v1.1.1 // indirect + github.com/golang/snappy v0.0.4 // indirect + github.com/klauspost/compress v1.16.7 // indirect + github.com/kr/pretty v0.3.0 // indirect + github.com/montanaflynn/stats v0.7.1 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/rogpeppe/go-internal v1.8.1 // indirect + github.com/xdg-go/pbkdf2 v1.0.0 // indirect + github.com/xdg-go/scram v1.1.2 // indirect + github.com/xdg-go/stringprep v1.0.4 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect + golang.org/x/crypto v0.26.0 // indirect + golang.org/x/sync v0.8.0 // indirect + golang.org/x/text v0.17.0 // indirect + gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect + gopkg.in/yaml.v3 v3.0.1 // indirect +) diff --git a/internal/test/goleak/go.sum b/internal/test/goleak/go.sum new file mode 100644 index 0000000000..dcf39d4358 --- /dev/null +++ b/internal/test/goleak/go.sum @@ -0,0 +1,74 @@ +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/klauspost/compress v1.16.7 h1:2mk3MPGNzKyxErAw8YaohYh69+pa4sIQSC0fPGCFR9I= +github.com/klauspost/compress v1.16.7/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= +github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= +github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.8.1 h1:geMPLpDpQOgVyCg5z5GoRwLHepNdb71NXb67XFkP+Eg= +github.com/rogpeppe/go-internal v1.8.1/go.mod h1:JeRgkft04UBgHMgCIwADu4Pn6Mtm5d4nPKWu0nJ5d+o= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= +github.com/xdg-go/pbkdf2 v1.0.0/go.mod h1:jrpuAogTd400dnrH08LKmI/xc1MbPOebTwRqcT5RDeI= +github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= +github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= +github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= +github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= +go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= +golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ= +golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= +golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= +golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= +gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= +gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/internal/test/goleak/goleak_test.go b/internal/test/goleak/goleak_test.go new file mode 100644 index 0000000000..83f82a9045 --- /dev/null +++ b/internal/test/goleak/goleak_test.go @@ -0,0 +1,122 @@ +// Copyright (C) MongoDB, Inc. 2024-present. +// +// Licensed under the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. You may obtain +// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + +package main + +import ( + "context" + "fmt" + "os" + "testing" + "time" + + "github.com/stretchr/testify/require" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" + "go.uber.org/goleak" +) + +var dbName = fmt.Sprintf("goleak-%d", time.Now().Unix()) + +// TestGoroutineLeak creates clients with various client configurations, runs +// some operations with each one, then disconnects the client. It asserts that +// no goroutines were leaked after the client is disconnected. +func TestGoroutineLeak(t *testing.T) { + testCases := []struct { + desc string + opts *options.ClientOptions + }{ + { + desc: "base", + opts: options.Client(), + }, + { + desc: "compressors=snappy", + opts: options.Client().SetCompressors([]string{"snappy"}), + }, + { + desc: "compressors=zlib", + opts: options.Client().SetCompressors([]string{"zlib"}), + }, + { + desc: "compressors=zstd", + opts: options.Client().SetCompressors([]string{"zstd"}), + }, + { + desc: "minPoolSize=10", + opts: options.Client().SetMinPoolSize(10), + }, + { + desc: "serverMonitoringMode=poll", + opts: options.Client().SetServerMonitoringMode(options.ServerMonitoringModePoll), + }, + } + + for _, tc := range testCases { + // These can't be run in parallel because goleak currently can't filter + // out goroutines from other parallel subtests. + t.Run(tc.desc, func(t *testing.T) { + defer goleak.VerifyNone(t) + + base := options.Client() + if u := os.Getenv("MONGODB_URI"); u != "" { + base.ApplyURI(u) + } + client, err := mongo.Connect(context.Background(), base, tc.opts) + require.NoError(t, err) + + defer func() { + err = client.Disconnect(context.Background()) + require.NoError(t, err) + }() + + db := client.Database(dbName) + defer func() { + err := db.Drop(context.Background()) + require.NoError(t, err) + }() + + coll := db.Collection(collectionName(t)) + + // Start a change stream to simulate a change listener workload. + cs, err := coll.Watch(context.Background(), mongo.Pipeline{}) + require.NoError(t, err) + defer cs.Close(context.Background()) + + // Run some Insert and FindOne operations to simulate a writing and + // reading workload. Run 50 iterations to increase the probability + // that a goroutine leak will happen if a problem exists. + for i := 0; i < 50; i++ { + _, err = coll.InsertOne(context.Background(), bson.M{"x": 123}) + require.NoError(t, err) + + var res bson.D + err = coll.FindOne(context.Background(), bson.D{}).Decode(&res) + require.NoError(t, err) + } + + // Intentionally cause some timeouts. Ignore any errors. + for i := 0; i < 50; i++ { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Microsecond) + coll.FindOne(ctx, bson.D{}).Err() + cancel() + } + + // Finish simulating the change listener workload. Use "Next" to + // fetch at least one change stream document batch and decode the + // first document. + cs.Next(context.Background()) + var res bson.D + err = cs.Decode(&res) + require.NoError(t, err) + }) + } +} + +func collectionName(t *testing.T) string { + return fmt.Sprintf("%s-%d", t.Name(), time.Now().Unix()) +} From 3cf0f9fc5281e86ffb4970c1fb8ba5e7a41284db Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Thu, 14 Nov 2024 09:30:39 -0800 Subject: [PATCH 2/4] Fix goleak module for v2. --- go.work | 1 + internal/test/goleak/go.mod | 10 +++------- internal/test/goleak/go.sum | 12 ++++++------ internal/test/goleak/goleak_test.go | 10 +++++----- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/go.work b/go.work index d1dbf036ba..e508be5714 100644 --- a/go.work +++ b/go.work @@ -8,4 +8,5 @@ use ( ./internal/cmd/benchmark ./internal/cmd/compilecheck ./internal/cmd/faas/awslambda/mongodb + ./internal/test/goleak ) diff --git a/internal/test/goleak/go.mod b/internal/test/goleak/go.mod index 8afebe5b6d..3f1fe31ac0 100644 --- a/internal/test/goleak/go.mod +++ b/internal/test/goleak/go.mod @@ -4,12 +4,9 @@ go 1.22 replace go.mongodb.org/mongo-driver => ../../../ -// Note that the Go driver version is replaced with the local Go driver code -// by the replace directive above. -require go.mongodb.org/mongo-driver v1.13.1 - require ( github.com/stretchr/testify v1.9.0 + go.mongodb.org/mongo-driver/v2 v2.0.0-beta2 go.uber.org/goleak v1.3.0 ) @@ -18,16 +15,15 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/klauspost/compress v1.16.7 // indirect github.com/kr/pretty v0.3.0 // indirect - github.com/montanaflynn/stats v0.7.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rogpeppe/go-internal v1.8.1 // indirect github.com/xdg-go/pbkdf2 v1.0.0 // indirect github.com/xdg-go/scram v1.1.2 // indirect github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect - golang.org/x/crypto v0.26.0 // indirect + golang.org/x/crypto v0.28.0 // indirect golang.org/x/sync v0.8.0 // indirect - golang.org/x/text v0.17.0 // indirect + golang.org/x/text v0.19.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/internal/test/goleak/go.sum b/internal/test/goleak/go.sum index dcf39d4358..9d10adb48a 100644 --- a/internal/test/goleak/go.sum +++ b/internal/test/goleak/go.sum @@ -15,8 +15,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= -github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= @@ -34,12 +32,14 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +go.mongodb.org/mongo-driver/v2 v2.0.0-beta2 h1:PRtbRKwblE8ZfI8qOhofcjn9y8CmKZI7trS5vDMeJX0= +go.mongodb.org/mongo-driver/v2 v2.0.0-beta2/go.mod h1:UGLb3ZgEzaY0cCbJpH9UFt9B6gEXiTPzsnJS38nBeoU= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw= +golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= @@ -59,8 +59,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.17.0 h1:XtiM5bkSOt+ewxlOE/aE/AKEHibwj/6gvWMl9Rsh0Qc= -golang.org/x/text v0.17.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/text v0.19.0 h1:kTxAhCbGbxhK0IwgSKiMO5awPoDQ0RpfiVYBfK860YM= +golang.org/x/text v0.19.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= diff --git a/internal/test/goleak/goleak_test.go b/internal/test/goleak/goleak_test.go index 83f82a9045..5ff16b750f 100644 --- a/internal/test/goleak/goleak_test.go +++ b/internal/test/goleak/goleak_test.go @@ -14,9 +14,9 @@ import ( "time" "github.com/stretchr/testify/require" - "go.mongodb.org/mongo-driver/bson" - "go.mongodb.org/mongo-driver/mongo" - "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/v2/bson" + "go.mongodb.org/mongo-driver/v2/mongo" + "go.mongodb.org/mongo-driver/v2/mongo/options" "go.uber.org/goleak" ) @@ -28,7 +28,7 @@ var dbName = fmt.Sprintf("goleak-%d", time.Now().Unix()) func TestGoroutineLeak(t *testing.T) { testCases := []struct { desc string - opts *options.ClientOptions + opts options.Lister[options.ClientOptions] }{ { desc: "base", @@ -66,7 +66,7 @@ func TestGoroutineLeak(t *testing.T) { if u := os.Getenv("MONGODB_URI"); u != "" { base.ApplyURI(u) } - client, err := mongo.Connect(context.Background(), base, tc.opts) + client, err := mongo.Connect(base, tc.opts) require.NoError(t, err) defer func() { From 3d2f24961e5c5c57691505063f6281bd0f634af2 Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:47:48 -0800 Subject: [PATCH 3/4] Use Taskfile to call the goleak test. --- .evergreen/config.yml | 7 ++----- Taskfile.yml | 2 ++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 91b9ddd23f..1f205185d4 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -392,12 +392,9 @@ functions: - command: shell.exec type: test params: - shell: "bash" - working_dir: src/go.mongodb.org/mongo-driver + binary: "bash" include_expansions_in_env: ["MONGODB_URI"] - script: | - ${PREPARE_SHELL} - bash etc/run-goleak-test.sh + args: [*task-runner, test-goleak] run-ocsp-server: - command: subprocess.exec diff --git a/Taskfile.yml b/Taskfile.yml index f22427a640..f65ab0df52 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -105,6 +105,8 @@ tasks: test-gcpkms: bash etc/run-gcpkms-test.sh + test-goleak: bash etc/run-goleak-test.sh + ### Local FaaS tasks. ### build-faas-awslambda: requires: From b8dafa22649f6101640ad338a36f51299c0bd475 Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Thu, 14 Nov 2024 10:49:04 -0800 Subject: [PATCH 4/4] Use subprocess.exec instead of shell.exec. --- .evergreen/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.evergreen/config.yml b/.evergreen/config.yml index 1f205185d4..04695353b6 100644 --- a/.evergreen/config.yml +++ b/.evergreen/config.yml @@ -389,7 +389,7 @@ functions: args: [*task-runner, run-docker] run-goleak-test: - - command: shell.exec + - command: subprocess.exec type: test params: binary: "bash"