[DRIVERS-421] Cursor iteration should complete (abnormally) when another thread closes the cursor Created: 10/Nov/17  Updated: 28/Oct/23  Resolved: 13/Feb/23

Status: Closed
Project: Drivers
Component/s: None
Fix Version/s: None

Type: Improvement Priority: Major - P3
Reporter: Jeffrey Yemin Assignee: Unassigned
Resolution: Fixed Votes: 0
Labels: newdriver
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on GODRIVER-125 Cursor iteration should complete (abn... Closed
depends on JAVA-2651 Unable to exit from hasNext() for tai... Closed
depends on CDRIVER-2361 Cursor iteration should complete (abn... Closed
depends on CSHARP-2092 Cursor iteration should complete (abn... Closed
depends on CXX-1469 Cursor iteration should complete (abn... Closed
depends on NODE-1185 Cursor iteration should complete (abn... Closed
depends on PHPC-1034 Cursor iteration should complete (abn... Closed
depends on PYTHON-1408 Cursor iteration should complete (abn... Closed
depends on RUST-168 Cursor iteration should complete (abn... Closed
depends on RUBY-1253 Cursor iteration should complete abno... Closed
Related
related to SERVER-21710 Allow pinned ClientCursors to be kill... Closed
Driver Changes: Needed
Driver Compliance:
Key Status/Resolution FixVersion
JAVA-2651 Fixed 3.6.0
NODE-1185 Works as Designed
SCALA-351 Works as Designed
PYTHON-1408 Fixed 3.6
CSHARP-2092 Fixed 2.10.0
PERL-815 Won't Fix
RUBY-1253 Fixed 2.18.2
CXX-1469 Works as Designed
PHPC-1034 Works as Designed
GODRIVER-125 Won't Fix
CDRIVER-2361 Works as Designed 1.9.0
RUST-168 Fixed 0.9.0-alpha
SWIFT-483 Won't Do

 Description   

In order to make cursor iteration blocking for tailable cursors, and in general to support the possibility of empty batches, driver implementations of cursor iteration typically have an inner loop within the method that advances the cursor:

        while (serverCursor != null) {
            _nextBatch = getMore();
            if (!_nextBatch.isEmpty()) {
                return true;  // has more results
            }
        }
        return false;  // no more results

Drivers should ensure that there is a check within that loop that the cursor has not been closed by another thread in the application.

        while (serverCursor != null) {
           _nextBatch = getMore();
            
           // if another thread closed the cursor, throw an exception so that this method terminates
           if (_closed) {
               throw ...  
           }
 
           if (!_nextBatch.isEmpty()) {
               return true;  // has more results
           }
        }
        return false;  // no more results

This is necessary because a call to killCursors from the close method of the cursor will fail if there is a getMore in progress on that cursor, and thus the repeated calls to getMore in the loop will never encounter a cursorNotFound error and the loop will not exit.



 Comments   
Comment by Derick Rethans [ 21/Nov/17 ]

Not applicable to PHPC (and PHPLIB)

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