Details
-
Bug
-
Resolution: Gone away
-
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.