[JAVA-4705] Setting a High Socket Read Timeout Value Leads to Integer Overflow Created: 10/Aug/22  Updated: 10/Oct/22

Status: Backlog
Project: Java Driver
Component/s: Configuration
Affects Version/s: 4.7.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: Ramasai Tadepalli Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related

 Description   

Summary

ServerSettings#heartbeatFrequencyMS defaults to 10,000 ms. If a very high value, let's say Integer.MAX_VALUE is provided as the socket read timeout, the socket read is going to be provided a timeout value of this high value + 10,000 ms. This leads to an integer overflow and pauses the pool after throwing a MongoConnectionPoolClearedException.

Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).

This has been observed with driver version 4.7 and server version 5.0.9. Other combinations have not been tested.

How to Reproduce

Steps to reproduce. If possible, please include a Short, Self Contained, Correct (Compilable), Example.

public static void main(String... args) {
        MongoClientSettings settings = MongoClientSettings.builder().applyToSocketSettings(builder -> {
            builder.readTimeout(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
            builder.connectTimeout(Integer.MAX_VALUE, TimeUnit.MILLISECONDS);
        }).applyToServerSettings(builder -> {
            builder.heartbeatFrequency(9999, TimeUnit.MILLISECONDS);
        }).build();
        MongoClient client = new MongoClient(settings);
        while (true) {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
 
            }
        }
    }

Additional Background

Please provide any additional background information that may be helpful in diagnosing the bug.
This can be reproduced non deterministically on 4.4.x+4422, but is always reproducible on 4.7.0.


Generated at Thu Feb 08 09:02:45 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.