[JAVA-4165] `ChangeStreamPublisher` may lose change events when retrying `getMore` Created: 17/May/21  Updated: 28/Oct/23  Resolved: 17/May/21

Status: Closed
Project: Java Driver
Component/s: Change Streams
Affects Version/s: 3.11.0
Fix Version/s: 4.3.0

Type: Bug Priority: Major - P3
Reporter: Valentin Kavalenka Assignee: Valentin Kavalenka
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Issue split
split from JAVA-4155 Investigate intermittent failures of ... Closed
Problem/Incident
causes JAVA-4166 Backport JAVA-4165 (`ChangeStreamPubl... Closed
Backwards Compatibility: Fully Compatible
Documentation Changes: Not Needed

 Description   

This bug description is a result of investigating JAVA-4155. The code

cursor.next(callback);
cachePostBatchResumeToken(cursor);

cursor.tryNext(callback);
cachePostBatchResumeToken(cursor);

in AsyncChangeStreamBatchCursor.java results in having a race condition: resumeToken may not yet be known when retrying the next/tryNext operation.



 Comments   
Comment by Jeffrey Yemin [ 27/Jul/21 ]

We never released 4.2.4 so changed the fix version to 4.3.0.

Comment by Githook User [ 17/May/21 ]

Author:

{'name': 'Valentin Kovalenko', 'email': 'valentin.kovalenko@mongodb.com', 'username': 'stIncMale'}

Message: `AsyncChangeStreamBatchCursor` must cache `resumeToken` after completion of the async `cursor.next`/`tryNext` operation (#713)

And also after extracting `resumeToken` from the received change stream documents
(this is also consistent with the behaviour of `ChangeStreamBatchCursor`).
Both updates to `resumeToken` must happen before completing the callback supplied to
`AsyncChangeStreamBatchCursor.next`/`tryNext`.

JAVA-4165
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/9a521f5dcfc95f4748abfa4bedd479753628509d

Comment by Jeffrey Yemin [ 17/May/21 ]

I think we should backport this for the 4.2.4 release

Generated at Thu Feb 08 09:01:23 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.