[GODRIVER-2080] Document client.StartSession does not error on disconnected client Created: 14/Jul/21  Updated: 28/Oct/23  Resolved: 29/Jul/21

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

Type: Improvement Priority: Minor - P4
Reporter: Marco Ottina Assignee: Benji Rewis (Inactive)
Resolution: Fixed Votes: 0
Labels: post-5.0
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Documentation Changes: Not Needed

 Description   

The invocation of `client.StartSession( aContext )` over a `*mongo.Client`  should produce an error if the client has been previously disconnected (through `client.Disconnect( aContext )` ). Am I missing something from the DOCS?The invocation of `client.StartSession( aContext )` over a `*mongo.Client`  should produce an error if the client has been previously disconnected (through `client.Disconnect( aContext )` ). Am I missing something from the DOCS?
To reproduce:

```
import (
"fmt"
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)

func main() {
    clientMongo, err := mongo.Connect(context.Background(), options.Client().ApplyURI( someUriYouProvide ))
   
    if err != nil

{       fmt.Printf("Should not error on creating a new valid adapter: %s \n.", err)     }

    err = clientMongo.Disconnect(context.Background()) // let simulate a connection loss
    if err != nil

{       fmt.Printf("error on disconnect: %s \n", err)     }

    // every operations over a Collection (obtained before the Disconnect) will now fail with an error, as expected
    mongoSession, err := clientMongo.StartSession()
    if err == nil

{       fmt.Println("should give error on starting session with DISCONNECTED mongo client")     }

}
```



 Comments   
Comment by Githook User [ 03/Aug/21 ]

Author:

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

Message: GODRIVER-2080 Document that StartSession does not error on disconnected client (#709)
Branch: release/1.7
https://github.com/mongodb/mongo-go-driver/commit/50c091af37fe516db57e24780042d574b4a62df4

Comment by Benji Rewis (Inactive) [ 29/Jul/21 ]

Updated documentation will be available in version 1.7.1 of the Go driver.

Comment by Githook User [ 29/Jul/21 ]

Author:

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

Message: GODRIVER-2080 Document that StartSession does not error on disconnected client (#709)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/ea04a2c8f126ed3bc2a7dd35e3309571381233dc

Comment by Marco Ottina [ 29/Jul/21 ]

Thank you so much for your kind help and replies.

Comment by Benji Rewis (Inactive) [ 29/Jul/21 ]

No problem. Here's a PR to document this behavior on client.StartSession https://github.com/mongodb/mongo-go-driver/pull/709

Comment by Marco Ottina [ 29/Jul/21 ]

First of all, thank you so much for your reply.
In fact, a Ping call would be sufficient to spot the disconnection.

It would be great if You would add that line to the Docs. Thank you so much.

Comment by Benji Rewis (Inactive) [ 28/Jul/21 ]

Hello ottins1995@gmail.com!

Thanks again for your report. Client.StartSession begins a session in the driver; it does not actually reach out to the server. StartSession simply constructs a new sessionImpl with the correct options and returns it to the caller. Because it does not reach out to the server, the StartSession method will not know that the client is currently disconnected, so it cannot return that error. However, attempting to use the session created in StartSession to communicate with the server should result in a mongo.ErrClientDisconnected.

If it would be helpful, we can add a small line in the documentation for that method clarifying that it does not actually perform any network calls.

Comment by Kevin Albertson [ 15/Jul/21 ]

Hello ottins1995@gmail.com, thank you for the report! We will further investigate this after we have completed high priority work for upcoming server support. Thank you for your patience.

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