[JAVA-3057] retryWrites URI option doesn't override MongoClientOptions Created: 19/Oct/18  Updated: 28/Oct/23  Resolved: 22/Oct/18

Status: Closed
Project: Java Driver
Component/s: Configuration
Affects Version/s: None
Fix Version/s: 3.9.0

Type: Bug Priority: Major - P3
Reporter: Kevin Pulo Assignee: Jeffrey Yemin
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
Case:
Backwards Compatibility: Minor Change

 Description   

When .retryWrites(true) is specified in the MongoClientOptions builder, passing retryWrites=false in the connection string URI doesn't disable retryable writes.

The bug appears to be that retryWrites are only set in the builder when retryWrites in the URI is set to true: https://github.com/mongodb/mongo-java-driver/blob/05d983e0e215a2e153129a5f61f81068329ff19a/driver-legacy/src/main/com/mongodb/MongoClientURI.java#L330

if (proxied.getRetryWrites()) {
    builder.retryWrites(proxied.getRetryWrites());
}

This code should instead set the builder retryWrites if retryWrites has been set at all in proxied (like how all the other options are handled), rather than only if it has been set to a true value.

Update

This bug manifests similarly if the application sets .retryWrites(true) is specified in the MongoClientOptions builder and doesn't specify retryWrites at all in the connection string. In this case the final value will be false rather than true.

Note also that this manifests as a similar bug in the new com.mongodb.MongoClientSettings class, and should be fixed there as well.



 Comments   
Comment by Githook User [ 22/Oct/18 ]

Author:

{'name': 'Jeff Yemin', 'email': 'jeff.yemin@10gen.com', 'username': 'jyemin'}

Message: Only apply retryWrites/compressors from connection string if set

JAVA-3057
JAVA-3058
Branch: master
https://github.com/mongodb/mongo-java-driver/commit/59906debe95ea760891c8bae855bca239575dc72

Generated at Thu Feb 08 08:58:41 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.