Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-3290

Change streams resume after thread is interrupted

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Change Streams
    • None

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: