[JAVA-4368] MongoCursor implementations should throw if iterated after close Created: 20/Oct/21  Updated: 03/Dec/21  Resolved: 03/Dec/21

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

Type: Bug Priority: Minor - P4
Reporter: Jeffrey Yemin Assignee: Jeffrey Yemin
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Currently, MongoCursor implementations may return results even after they have been closed, because they are relying on the underlying BatchCursor to throw an exception, even though it's still possible to return results from the current batch, e.g.

var cursor = collection.find().cursor();
cursor.next();
cursor.close();
cursor.next();   // should throw, but does not if the first batch has > 1 results



 Comments   
Comment by Jeffrey Yemin [ 03/Dec/21 ]

close is allowed to be called concurrently with iteration methods, which requires at minimum that we add a volatile field that is set in close and checked in iteration methods.. There is some cost to that, and it's not clear that it's worth the benefit that we get from throwing while iterating a closed cursor, given how rare that should be in practice.

Closing as Won't Fix.

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