CSOT: a SocketTimeoutException during a write isn't translated to MongoOperationTimeoutException

XMLWordPrintableJSON

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

      Component: driver-core (com.mongodb.internal.connection)
      Related: JAVA-6057

      Description

      With timeoutMS set, socket timeouts should surface as MongoOperationTimeoutException. This translation happens on the read path but not the write path: InternalStreamConnection.throwTranslatedWriteException(...) only converts MongoSocketWriteTimeoutException, so a bare java.net.SocketTimeoutException on write falls through to MongoSocketWriteException. translateReadException(...) already translates a bare SocketTimeoutException — the two paths are inconsistent.

      Reproduces on Windows + TLS (shouldUseConnectTimeoutMsWhenEstablishingConnectionInBackground, all topologies):

      expected  but was 
      Caused by: java.net.SocketTimeoutException: Read timed out
      

      On Windows an SSLSocket write blocks reading TLS records, so the read-timeout fires during the send and reaches the write path.

      Fix

      In throwTranslatedWriteException, when hasTimeoutMS(), translate a bare SocketTimeoutException to MongoOperationTimeoutException (mirroring the read path); add a test.

      Why this is not a backwards-breaking change

      • No API change — no signatures, public types, or method contracts change; fully binary-compatible.
      • Behaviour change is confined to the timeoutMS (CSOT) path, and only when a socket timeout occurs during a write. It swaps one MongoException subtype for another (MongoSocketWriteException -> MongoOperationTimeoutException).
      • The new exception is the correct/documented one — the operation genuinely timed out under timeoutMS, and the CSOT contract specifies MongoOperationTimeoutException for that case. The old behaviour was an inconsistency, not a contract.
      • It makes write consistent with read, which already returns MongoOperationTimeoutException for the same underlying SocketTimeoutException.

            Assignee:
            Ross Lawley
            Reporter:
            Ross Lawley
            None
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: