[GODRIVER-2533] Data race when fetching the number of sessions in progress Created: 24/Aug/22  Updated: 28/Oct/23  Resolved: 04/Oct/22

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: None
Fix Version/s: 1.10.3

Type: Bug Priority: Unknown
Reporter: Ivaylo Novakov Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

Summary

Calling db.Client().NumberSessionsInProgress() from one goroutine triggers the data race detector when other goroutines are working with the database calling CountDocuments() or other operation.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

Driver version  v1.10.1.

Topology: replica set with a single server.

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

 

func TestDataRace(t *testing.T) {
    ctx := context.Background()
    connStr := database.ConnectionString(test.DBTestCredentials())
    c, _ := mongo.NewClient(options.Client().ApplyURI(connStr))
    _ = c.Connect(ctx)
    db := c.Database("races")}}{{    go func() {
        for {
            _ = db.Client().NumberSessionsInProgress()
        }
    }()
    go func() {
        for {
            _, _ = db.Collection("users").CountDocuments(ctx, bson.M{})
        }
    }()
    time.Sleep(time.Second)
}

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.



 Comments   
Comment by Ivaylo Novakov [ 04/Oct/22 ]

Happy to help!

Thanks for the fix!

Comment by Benji Rewis (Inactive) [ 04/Oct/22 ]

Thanks again for your bug report inovakov@gmail.com. We've changed checkedOut to be an atomically-accessed int64, and the fix will be backported to the upcoming 1.10.3 version of the Go driver.

Comment by Githook User [ 04/Oct/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2533 Fix data race from NumberSessionsInProgress. (#1085)
Branch: release/1.10
https://github.com/mongodb/mongo-go-driver/commit/b504c38406a5e7c45e1f77a8d2d9e938358cc695

Comment by Githook User [ 04/Oct/22 ]

Author:

{'name': 'Benjamin Rewis', 'email': '32186188+benjirewis@users.noreply.github.com', 'username': 'benjirewis'}

Message: GODRIVER-2533 Fix data race from NumberSessionsInProgress. (#1085)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/1205fe400cfecacbb7c98aa3bb923eb4fb0d16c7

Comment by Benji Rewis (Inactive) [ 04/Oct/22 ]

https://github.com/mongodb/mongo-go-driver/pull/1085

Comment by Benji Rewis (Inactive) [ 26/Sep/22 ]

inovakov@gmail.com thanks so much for your report and apologies for the delay! We're investigating this data race now.

Comment by Ivaylo Novakov [ 24/Aug/22 ]

The rich text formatting garbled the code a bit, so here is an unformatted copy.

 

 

 

func TestDataRace(t *testing.T) {
    ctx := context.Background()
    connStr := database.ConnectionString(test.DBTestCredentials())
    c, _ := mongo.NewClient(options.Client().ApplyURI(connStr))
    _ = c.Connect(ctx)
    db := c.Database("races")

    go func() {
        for

{             _ = db.Client().NumberSessionsInProgress()         }

    }()
    go func() {
        for {
            _, _ = db.Collection("users").CountDocuments(ctx, bson.M{})
        }
    }()
    time.Sleep(time.Second)
}

Generated at Thu Feb 08 08:38:51 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.