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

Failure to propagate IO exceptions in Asynchronous callbacks

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 5.2.0
    • Affects Version/s: None
    • Component/s: None
    • None
    • Java Drivers
    • Not Needed
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      The current implementation of the asynchronous API fails fails to propagate IOException from asynchronous IO to the callback, meaning users will never see an exception from IO operations. When throwTranslatedWriteException throws exception from thenRunTryCatchAsyncBlocks() method's error handler in the asynchronous API, the exception is propagated to a thread and not passed to the callback, rendering the error unobservable by a user.

      This issue has been observed in the false positive test of InternalStreamConnectionSpecification (should notify all asynchronous writers of an exception), which aims to notify all asynchronous writers of an exception but takes an excessively long time (approximately 3 minutes) to complete.

      The following example code mimics the issue and illustrates the error handling in the current implementation:

      SingleResultCallback<Void> callback = (v, e) -> {
          if (e != null) {
              System.err.println("Error " + e);
          } else {
              System.err.println("Done successfully");
          }
      };
      
      
      beginAsync().thenRun(c -> {
          c.complete(c);
      }).thenRunTryCatchAsyncBlocks(c -> {
          new Thread() {
              public void run() {
                 c.completeExceptionally(new IOException("Socket timeout"));
              }
          }.start();
      }, Throwable.class, (t, c) -> {
          throw new MongoSocketWriteException("Socket write error", null, t);
      }).finish(callback);

            Assignee:
            slav.babanin@mongodb.com Slav Babanin
            Reporter:
            slav.babanin@mongodb.com Slav Babanin
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: