Draft
Conversation
- Make MongoOperationTimeoutException extend MongoClientException instead of MongoTimeoutException to avoid breaking the semantic guarantee that MongoTimeoutException implies the operation was not executed - Handle MongoOperationTimeoutException explicitly in instanceof MongoTimeoutException checks to preserve existing behavior for transaction labeling, connection pool events, and logging JAVA-5438
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the Java driver’s timeout exception semantics by removing the inheritance relationship between MongoOperationTimeoutException and MongoTimeoutException, so that catching MongoTimeoutException continues to imply “timed out waiting for a server/connection” (i.e., the operation was not executed).
Changes:
- Changed
MongoOperationTimeoutExceptionto extendMongoClientExceptioninstead ofMongoTimeoutException. - Updated transaction error labeling and commit labeling logic to treat
MongoOperationTimeoutExceptionas a timeout-equivalent case. - Updated connection pool/server selection timeout handling and structured logging logic to explicitly account for
MongoOperationTimeoutException.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| driver-sync/src/main/com/mongodb/client/internal/MongoClusterImpl.java | Adds MongoOperationTimeoutException handling when applying transient transaction error labels. |
| driver-reactive-streams/src/main/com/mongodb/reactivestreams/client/internal/OperationExecutorImpl.java | Adds MongoOperationTimeoutException handling when applying transient transaction error labels in reactive execution. |
| driver-core/src/main/com/mongodb/MongoOperationTimeoutException.java | Changes the exception superclass to MongoClientException to avoid implying “not executed” semantics. |
| driver-core/src/main/com/mongodb/internal/operation/CommitTransactionOperation.java | Treats MongoOperationTimeoutException as eligible for UnknownTransactionCommitResult labeling decisions. |
| driver-core/src/main/com/mongodb/internal/connection/LoadBalancedCluster.java | Broadens timeout-exception factory return type and ensures timeoutMS produces MongoOperationTimeoutException. |
| driver-core/src/main/com/mongodb/internal/connection/DefaultConnectionPool.java | Ensures connection checkout failure classification/maintenance handling treats MongoOperationTimeoutException as a timeout. |
| driver-core/src/main/com/mongodb/internal/connection/BaseCluster.java | Ensures server selection timeout creation/logging properly accounts for MongoOperationTimeoutException. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MongoTimeoutException is stable public API documented as "waiting for a server or connection to become available," implying the operation was not executed. MongoOperationTimeoutException does not provide that guarantee: the operation may have been sent to the server and may have executed. Keeping it as a subclass of MongoTimeoutException is therefore semantically incorrect and may mislead consumers that catch MongoTimeoutException into assuming no operation was executed.
Changes:
Options considered:
JAVA-5438