Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-910

panic when calling Watch on a Client that has not been connected

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 1.0.1
    • Affects Version/s: 1.0.0
    • Component/s: CRUD
    • None

      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.

            Assignee:
            isabella.siu@mongodb.com Isabella Siu (Inactive)
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: