@@ -278,6 +278,9 @@ func (c *Client) Ping(ctx context.Context, rp *readpref.ReadPref) error {
278
278
// StartSession does not actually communicate with the server and will not error if the client is
279
279
// disconnected.
280
280
//
281
+ // StartSession is safe to call from multiple goroutines concurrently. However, Sessions returned by StartSession are
282
+ // not safe for concurrent use by multiple goroutines.
283
+ //
281
284
// If the DefaultReadConcern, DefaultWriteConcern, or DefaultReadPreference options are not set, the client's read
282
285
// concern, write concern, or read preference will be used, respectively.
283
286
func (c * Client ) StartSession (opts ... * options.SessionOptions ) (Session , error ) {
@@ -1023,6 +1026,9 @@ func (c *Client) ListDatabaseNames(ctx context.Context, filter interface{}, opts
1023
1026
// SessionContext must be used as the Context parameter for any operations in the fn callback that should be executed
1024
1027
// under the session.
1025
1028
//
1029
+ // WithSession is safe to call from multiple goroutines concurrently. However, the SessionContext passed to the
1030
+ // WithSession callback function is not safe for concurrent use by multiple goroutines.
1031
+ //
1026
1032
// If the ctx parameter already contains a Session, that Session will be replaced with the one provided.
1027
1033
//
1028
1034
// Any error returned by the fn callback will be returned without any modifications.
@@ -1035,6 +1041,9 @@ func WithSession(ctx context.Context, sess Session, fn func(SessionContext) erro
1035
1041
// be executed under a session. After the callback returns, the created Session is ended, meaning that any in-progress
1036
1042
// transactions started by fn will be aborted even if fn returns an error.
1037
1043
//
1044
+ // UseSession is safe to call from multiple goroutines concurrently. However, the SessionContext passed to the
1045
+ // UseSession callback function is not safe for concurrent use by multiple goroutines.
1046
+ //
1038
1047
// If the ctx parameter already contains a Session, that Session will be replaced with the newly created one.
1039
1048
//
1040
1049
// Any error returned by the fn callback will be returned without any modifications.
@@ -1043,6 +1052,9 @@ func (c *Client) UseSession(ctx context.Context, fn func(SessionContext) error)
1043
1052
}
1044
1053
1045
1054
// UseSessionWithOptions operates like UseSession but uses the given SessionOptions to create the Session.
1055
+ //
1056
+ // UseSessionWithOptions is safe to call from multiple goroutines concurrently. However, the SessionContext passed to
1057
+ // the UseSessionWithOptions callback function is not safe for concurrent use by multiple goroutines.
1046
1058
func (c * Client ) UseSessionWithOptions (ctx context.Context , opts * options.SessionOptions , fn func (SessionContext ) error ) error {
1047
1059
defaultSess , err := c .StartSession (opts )
1048
1060
if err != nil {
0 commit comments