[JAVA-4283] Calling watch() for changestream will send getMore command forever Created: 30/Aug/21 Updated: 27/Oct/23 Resolved: 03/Sep/21 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | Change Streams |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Unknown |
| Reporter: | James Chen | Assignee: | Valentin Kavalenka |
| Resolution: | Works as Designed | Votes: | 0 |
| Labels: | external-user | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Documentation Changes: | Not Needed |
| Description |
|
Env: mongo-java-reactivestreams v4.3.1 Reproduce steps: Just Call
to watch a collection for changestream
Logs:
As you can see from the logs, it sent getMore commands with the same cursor ID everytime ("getMore": 4558344685700738737 ), which makes it never stop. And I guess the bug is caused by: com.mongodb.internal.operation.AsyncQueryBatchCursor.CommandResultSingleResultCallback#onResult **, which parses the query cursor ID from the response and uses the same cursor ID to query next batch and just loop forever. |
| Comments |
| Comment by Valentin Kavalenka [ 03/Sep/21 ] |
|
What you described is the intended behavior of a ChangeStreamPublisher object you get from com.mongodb.reactivestreams.client.MongoCollection.watch(Class): it watches for changes in the collection and publishes corresponding change events. The way ChangeStreamPublisher, or ChangeStreamIterable in synchronous API, does this is by issuing getMore commands, usually until the corresponding org.reactivestreams.Subscription / MongoChangeStreamCursor is cancelled / closed. Each getMore command is blocked by the server until either its maxTimeMS expires, or there are new change events to return. You may change this duration via ChangeStreamPublisher.maxAwaitTime(long, TimeUnit) / ChangeStreamIterable.maxAwaitTime(long, TimeUnit), as per the description of maxAwaitTimeMS in https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#driver-api. |
| Comment by James Chen [ 30/Aug/21 ] |
|
The version of MongoDB is: v4.4.8 |