Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2135

Race condition in connection pool coordinator

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Unknown Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None

      go.mod

      module main
      
      go 1.16
      
      require go.mongodb.org/mongo-driver v1.7.1 // indirect
      

      main.go

      Unable to find source-code formatter for language: golang. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      package main
       
      import (
         "context"
       
         "go.mongodb.org/mongo-driver/mongo"
         "go.mongodb.org/mongo-driver/mongo/options"
         "go.mongodb.org/mongo-driver/mongo/readpref"
       
         "time"
      )
       
      func main() {
         ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
         defer cancel()
       
         client, err := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017/?minPoolSize=5"))
         if err != nil {
            panic(err)
         }
       
         err = client.Ping(ctx, readpref.Primary())
         if err != nil {
            panic(err)
         }
      }
      

      Running the above with go run -race main.go will produce:

      ==================
      WARNING: DATA RACE
      Read at 0x00c0001dae00 by main goroutine:
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*pool).stale()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:199 +0x235
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.connectionExpiredFunc()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:97 +0x1e5
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*resourcePool).Get()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/resource_pool.go:125 +0x20c
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*pool).get()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:388 +0x3f9
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*Server).Connection()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/server.go:268 +0xf4
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*SelectedServer).Connection()
            <autogenerated>:1 +0x78
        go.mongodb.org/mongo-driver/x/mongo/driver.Operation.getServerAndConnection()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/operation.go:246 +0x113
        go.mongodb.org/mongo-driver/x/mongo/driver.Operation.Execute()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/operation.go:301 +0x117
        go.mongodb.org/mongo-driver/x/mongo/driver/operation.(*Command).Execute()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/operation/command.go:104 +0x34e
        go.mongodb.org/mongo-driver/mongo.(*Database).RunCommand()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/mongo/database.go:203 +0x284
        go.mongodb.org/mongo-driver/mongo.(*Client).Ping()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/mongo/client.go:265 +0x23a
        main.main()
            /home/alex/Workspace/go1/main.go:22 +0x1ca
      
      Previous write at 0x00c0001dae00 by goroutine 14:
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*connection).connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/connection.go:231 +0x106b
      
      Goroutine 14 (finished) created at:
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*pool).connectionInitFunc()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:134 +0xaf
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*pool).connectionInitFunc-fm()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:128 +0x4a
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*resourcePool).add()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/resource_pool.go:102 +0x1fc
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*resourcePool).Maintain()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/resource_pool.go:210 +0x26f
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*resourcePool).initialize()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/resource_pool.go:95 +0x124
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*pool).connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/pool.go:208 +0xaa
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*Server).Connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/server.go:215 +0x239
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.ConnectServer()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/server.go:136 +0xe9
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*Topology).addServer()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/topology.go:686 +0x1a6
        go.mongodb.org/mongo-driver/x/mongo/driver/topology.(*Topology).Connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/x/mongo/driver/topology/topology.go:213 +0x10af
        go.mongodb.org/mongo-driver/mongo.(*Client).Connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/mongo/client.go:156 +0x6fb
        go.mongodb.org/mongo-driver/mongo.Connect()
            /home/alex/.gvm/pkgsets/go1.16.7/global/pkg/mod/go.mongodb.org/mongo-driver@v1.7.1/mongo/client.go:106 +0x90
        main.main()
            /home/alex/Workspace/go1/main.go:17 +0x16e
      ==================
      Found 1 data race(s)
      exit status 66
      

      Race condition exists for any value of minPoolSize greater than 0.

            Assignee:
            Unassigned Unassigned
            Reporter:
            alex.bevilacqua@mongodb.com Alex Bevilacqua
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: