[GODRIVER-374] examples_test.go : Topology is closed on Mac Created: 22/Apr/18  Updated: 28/Oct/23  Resolved: 01/May/18

Status: Closed
Project: Go Driver
Component/s: Testing
Affects Version/s: 0.0.3
Fix Version/s: 0.0.4

Type: Bug Priority: Blocker - P1
Reporter: Thomas Geulen Assignee: Kristofer Brandow (Inactive)
Resolution: Fixed Votes: 1
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

macOS High Sierra



 Description   

It's not possible to connect to a running mongod instance on a Mac.
Even the provided test example fails with the following message:

— FAIL: TestDocumentationExamples (0.00s)
Error Trace: examples.go:60
examples_test.go:26
Error: Received unexpected error:
topology is closed
FAIL
FAIL command-line-arguments 0.014s



 Comments   
Comment by Githook User [ 30/Apr/18 ]

Author:

{'email': 'kris@mongodb.com', 'username': 'skriptble', 'name': 'Kris Brandow'}

Message: Fix documentation examples

GODRIVER-374

Change-Id: I7fe2c76a0ae825af5beb9f4d0242239018e173f1
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/ae1ce2a1a38e61d4be4c3b31fe7ca698e9983c1e

Comment by Kristofer Brandow (Inactive) [ 30/Apr/18 ]

Code Review: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/409516.

Comment by Kristofer Brandow (Inactive) [ 23/Apr/18 ]

Given that both of you had trouble with this, I think we need to better document the new behavior of Client. As part of GODRIVER-285, we added the ability disconnect and reconnect a Client. We also changed it so that NewClient doesn't actually start goroutines and just instantiates a *mongo.Client instances. To actually use the Client you now need to call Connect, alternatively you can use mongo.Connect which will create a Client and connect it. There will be further changes coming to the Client design when GODRIVER-348 is completed.

I've created GODRIVER-378 to help clarify this issue in the future and give better direction for users.

Comment by Ad [ 23/Apr/18 ]

Just tried something inside the lib.
I have added: topo.Connect(context.Background())
and it works

func newClient(cs connstring.ConnString, opts *ClientOptions) (*Client, error) {
	client := &Client{
		connString:     cs,
		localThreshold: defaultLocalThreshold,
		readPreference: readpref.Primary(),
	}
 
	if opts != nil {
		for opts.opt != nil {
			err := opts.opt(client)
			if err != nil {
				return nil, err
			}
			opts = opts.next
		}
	}
 
	topts := append(
		client.topologyOptions,
		topology.WithConnString(func(connstring.ConnString) connstring.ConnString { return client.connString }),
	)
	topo, err := topology.New(topts...)
	if err != nil {
		return nil, err
	}
 
	topo.Connect(context.Background())
	client.topology = topo
	client.readConcern = readConcernFromConnString(&client.connString)
	client.writeConcern = writeConcernFromConnString(&client.connString)
 
	return client, nil
}

Comment by Ad [ 23/Apr/18 ]

Having the same issue here.

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