Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-4705

Setting a High Socket Read Timeout Value Leads to Integer Overflow

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: 4.7.0
    • Component/s: Configuration
    • Labels:
      None

      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.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ramasai.tadepalli@mongodb.com Ramasai Tadepalli
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: