-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
The Go Documentation on ChangeStream.Close says
Next and TryNext must not be called after Close has been called.
If this is not honored by a user, they can get a fairly confusing panic:
go.mongodb.org/mongo-driver/mongo.(*ChangeStream).loopNext(0xc000002140, {0x124ca00, 0x18e8040}, 0x0) /go/pkg/mod/go.mongodb.org/mongo-driver@v1.12.1/mongo/change_stream.go:658 +0x6b go.mongodb.org/mongo-driver/mongo.(*ChangeStream).next(0xc000002140, {0x124ca00?, 0x18e8040?}, 0xd0?) /go/pkg/mod/go.mongodb.org/mongo-driver@v1.12.1/mongo/change_stream.go:627 +0x5d go.mongodb.org/mongo-driver/mongo.(*ChangeStream).Next(...) /go/pkg/mod/go.mongodb.org/mongo-driver@v1.12.1/mongo/change_stream.go:598 draw-platform/storage/mongodb.(*StorageCollection).WatchRunnerResponse.func1()
See here for an example: https://gist.github.com/prestonvasquez/30f15e9f84c76a63e6bf818663a18309
The Go Driver could communicate to the Next / TryNext method from the Close method using a buffered channel, something like this:
// This would be in the Next function: select { case <-close: // chan struct{} // Close the change stream. return default: // Run the next logic }
Definition of done: determine if this change is worth doing or not, if it is worth doing then implement the change.
- related to
-
GODRIVER-2959 Mongodb watch change stream will panic, when no data be found by query condition
- Closed