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

Panic when Change Stream is closed

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.4
    • Component/s: CRUD
    • Labels:
      None

      The following code, that opens a change stream and closes it while the iterator is waiting for an event, panics on master:
       

      package main
      
      import (
         "context"
         "fmt"
         "time"
      
         "go.mongodb.org/mongo-driver/bson"
         "go.mongodb.org/mongo-driver/mongo"
         "go.mongodb.org/mongo-driver/mongo/options"
      )
      
      func main() {
         opts := options.Client().ApplyURI("mongodb://0.0.0.0/issue")
      
         client, err := mongo.Connect(nil, opts)
         if err != nil {
            panic(err)
         }
      
         db := client.Database("issue")
      
         cs, err := db.Collection("foo").Watch(context.Background(), []bson.M{}, options.ChangeStream())
         if err != nil {
            panic(err)
         }
         defer cs.Close(nil)
      
         go func() {
            time.Sleep(time.Second)
            cs.Close(nil)
         }()
      
         for cs.Next(context.Background()) {
            fmt.Println(cs.Current)
         }
      }
      

       

      panic: runtime error: invalid memory address or nil pointer dereference
      [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x13ae12d]
      
      goroutine 1 [running]:
      go.mongodb.org/mongo-driver/mongo.(*ChangeStream).loopNext(0xc000102960, 0x15d08c0, 0xc0000a6008)
      	/Users/256dpi/Development/Go/pkg/mod/go.mongodb.org/mongo-driver@v1.0.1-0.20190712184055-9ec4480161a7/mongo/change_stream.go:452 +0x15d
      go.mongodb.org/mongo-driver/mongo.(*ChangeStream).Next(0xc000102960, 0x15d08c0, 0xc0000a6008, 0x0)
      	/Users/256dpi/Development/Go/pkg/mod/go.mongodb.org/mongo-driver@v1.0.1-0.20190712184055-9ec4480161a7/mongo/change_stream.go:420 +0x151
      main.main()
      	/Users/256dpi/Development/GitHub/256dpi/fire/spark/issue/main.go:34 +0x35c
      

            Assignee:
            manny.eppinger@mongodb.com Emmanuel Eppinger (Inactive)
            Reporter:
            joel.gaehwiler@gmail.com Joël Gähwiler
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: