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

Watching a ChangeStream doesn't handle Disconnect/Reconnect

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Gone away
    • Icon: Major - P3 Major - P3
    • None
    • None
    • None
    • None

    Description

      Using the following code

      ctx := context.Background()
       
      c := h.db.Collection("col")
      cs, err := c.Watch(ctx, []bson.M{})
      if err != nil {
      	log.Println("cannot watch for changes", err)
      }
      defer cs.Close(ctx)
       
      for cs.Next(ctx) {
      	doc := bson.M{}
      	if err := cs.Decode(&doc); err != nil {
      		continue
      	}
       
      	// do something with doc
      }
       
      if cs.Err() != nil {
      	log.Println("error reading changestream", cs.Err())
      }
      

       
      When the MongoDB server goes down or gets restarted, the for loop keeps hanging and doesn't receive any more data or error.
      Working with a time-constrained context seems wrong, since I actually want to listen endlessly.
      IMHO either the driver should silently handle the reconnect and setup the change stream again, or it should properly signal the lost session/connection by returning from the Next() call with an error, so I have a chance to reestablish the change stream myself.

      Attachments

        Activity

          People

            divjot.arora@mongodb.com Divjot Arora (Inactive)
            aksdb Andreas Schneider
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: