Close connection on responseTo mismatch and harden async error handling to prevent stream desynchronization

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: Connection Management
    • None
    • Java Drivers
    • Not Needed
    • None
    • None
    • None
    • None
    • None
    • None

      Two categories of issue were identified in InternalStreamConnection:

      1. No connection close on responseTo mismatch detection

      getCommandResult() detects the mismatch and throws MongoInternalException, but callers in both the sync (sendAndReceive) and async (sendCommandMessageAsync) paths did not catch
      MongoInternalException separately — it fell through to the generic Exception handler which does not close the connection. The corrupted connection was returned to the pool and reused.

      2. catch(Exception) misses Error subclasses in async paths

      Three locations caught Exception instead of Throwable, meaning an OutOfMemoryError (or any Error) during async I/O would bypass the close() call:

      • readAsync()catch (Exception e) did not catch Error
      • sendMessageAsync()thenRunTryCatchAsyncBlocks was parameterized with Exception.class instead of Throwable.class
      • MessageHeaderCallback.onResult() — caught Throwable but did not call close() before invoking the callback

            Assignee:
            Ross Lawley
            Reporter:
            Ross Lawley
            Almas Abdrazak, Nabil Hachicha
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: