[JAVA-2965] maxAwaitTime not working on a change stream Created: 08/Sep/18  Updated: 14/Sep/18  Resolved: 14/Sep/18

Status: Closed
Project: Java Driver
Component/s: Query Operations
Affects Version/s: 3.8.0
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Chris Assignee: Jeffrey Yemin
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

I'm using the java driver version 3.8.0 and mongodb 3.6.

The documentation here states about maxAwaitTime:

The maximum amount of time for the server to wait on new documents to satisfy a change stream query.

However, what I'm seeing is that cursor.hasNext() returns only if there is a change on the collection, never when the time passed to maxAwaitTime has elapsed.

When I turn on mongodb's verbose logging I see maxWaitTime set as expected in the getMore command.

Is maxAwaitTime supposed to cause my watch to timeout when there are no changes?



 Comments   
Comment by Jeffrey Yemin [ 10/Sep/18 ]

Hi crummel

The driver is working as designed, though I see why it's confusing.  While the server's getMore command will return after maxAwaitTime if no documents are found that match the query, the next or hasNext methods on MongoCursor will not.  Rather, it will continue to call the getMore command in a loop until either a document is returned, the cursor is closed, or an exception occurs.  This is a consequence of the way the Iterator interface is specified in Java.

If your application requires a time out after maxAwaitTime, the Java driver offers the tryNext method on MongoCursor. This method will return null after maxAwaitTime if no documents were found, and can be called repeatedly by the application.

Generated at Thu Feb 08 08:58:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.