[GODRIVER-910] panic when calling Watch on a Client that has not been connected Created: 28/Mar/19  Updated: 28/Oct/23  Resolved: 29/Mar/19

Status: Closed
Project: Go Driver
Component/s: CRUD
Affects Version/s: 1.0.0
Fix Version/s: 1.0.1

Type: Bug Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Isabella Siu (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

With

	client, _ := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
 
	// Oops, forgot to call client.Connect!
 
	_, _ = client.Watch(context.Background(), []bson.D{})

the driver panics with

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x11ee797]
 
goroutine 1 [running]:
test/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session.(*Pool).GetSession(0x0, 0x0, 0x0, 0x0)
	/Users/jeff/gopath/src/test/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session/session_pool.go:65 +0x37
test/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session.NewClientSession(0x0, 0x4e488c3dec7e45be, 0xa1fec4774c4f35b9, 0x1, 0x0, 0x0, 0x0, 0x185c3d0, 0x0, 0x0)
	/Users/jeff/gopath/src/test/vendor/go.mongodb.org/mongo-driver/x/mongo/driver/session/client_session.go:150 +0x100
test/vendor/go.mongodb.org/mongo-driver/mongo.getSession(0x159b380, 0xc00001e090, 0xc000012580, 0xc0000805a0, 0x2, 0x2, 0x185c3d0)
	/Users/jeff/gopath/src/test/vendor/go.mongodb.org/mongo-driver/mongo/change_stream.go:149 +0x10b
test/vendor/go.mongodb.org/mongo-driver/mongo.newClientChangeStream(0x159b380, 0xc00001e090, 0xc000012580, 0x13de920, 0xc00000c820, 0x0, 0x0, 0x0, 0x13de920, 0x1, ...)
	/Users/jeff/gopath/src/test/vendor/go.mongodb.org/mongo-driver/mongo/change_stream.go:361 +0x1d5
test/vendor/go.mongodb.org/mongo-driver/mongo.(*Client).Watch(0xc000012580, 0x159b380, 0xc00001e090, 0x13de920, 0xc00000c820, 0x0, 0x0, 0x0, 0x10071d0, 0xc000082058, ...)
	/Users/jeff/gopath/src/test/vendor/go.mongodb.org/mongo-driver/mongo/client.go:533 +0x84

I'd expected a disconnected client to error, not panic.



 Comments   
Comment by Githook User [ 29/Mar/19 ]

Author:

{'email': 'isabella.siu@10gen.com', 'name': 'Isabella Siu', 'username': 'iwysiu'}

Message: GODRIVER-910 don't panic when calling watch on a disconnected client

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

Comment by Isabella Siu (Inactive) [ 29/Mar/19 ]

code review url: https://review.gerrithub.io/c/mongodb/mongo-go-driver/+/449554

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