[CXX-2278] [ChangeStream] Why does iterating change stream block and how to avoid it Created: 09/Jun/21  Updated: 27/Oct/23  Resolved: 30/Jun/21

Status: Closed
Project: C++ Driver
Component/s: Implementation
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Unknown
Reporter: Puya Daravi Assignee: Kevin Albertson
Resolution: Gone away Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CXX-2441 Add example of iterating change strea... Closed

 Description   

Hello,

I am trying to use change streams and this code snippet is blocking:

for (const auto& event : stream)
{
    handleEvent(event);
}

I run the above code periodically on different streams. But I see that stream iteration blocks when it is empty and I am not able to break out of this loop if that happens. Why is that the case? How can I read all available events in the stream and not be blocked? I cannot use a break; since I don't know before reading the stream how many events are in there.



 Comments   
Comment by Backlog - Core Eng Program Management Team [ 30/Jun/21 ]

There hasn't been any recent activity on this ticket, so we're resolving it. Thanks for reaching out! Please feel free to comment on this if you're able to provide more information.

Comment by Puya Daravi [ 15/Jun/21 ]

Hi kevin.albertson, I had set the max_await_time to 1000, but the iterator was blocking for ever after it reached the end of the stream (100 entries). This should not have happened correct? I will try to create a minimum reproducible example.

Comment by Kevin Albertson [ 14/Jun/21 ]

Hi puya@motionmetrics.com, thank you for the report!

The server will block for a period of time to wait for events to be generated on iteration. That can be configured with the max_await_time option.

Generated at Wed Feb 07 22:05:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.