[JAVA-3290] Change streams resume after thread is interrupted Created: 16/May/19  Updated: 13/Jun/19  Resolved: 16/May/19

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

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

Issue Links:
Duplicate
is duplicated by JAVA-3291 ChangeStreamBatchCursor is not interr... Closed

 Description   

This should interrupt the change stream:

final Thread t =
    new Thread(
        () -> {
          try {
            for (final ChangeStreamDocument<Document> doc : collection.watch()) {
              System.out.println(doc);
            }
          } catch (final MongoInterruptedException e) {
           System.out.println("interrupted");
          }
        });
 
t.start();
 
Thread.sleep(1000);
 
t.interrupt();
t.join();

but it doesn't.

The workaround is to instead close the MongoCursor, but that's more awkward than just interrupting a thread.

There are a number of reasons why this doesn't work now:

  • Sockets are not interruptible, so Thread.interrupt() is ignored when waiting on Socket.read
  • Even if they were, MongoInterruptedException is treated as a retryable error for change streams. It should not be.


 Comments   
Comment by Jeffrey Yemin [ 16/May/19 ]

Duplicates JAVA-3291

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