Socket timeout with mongo DB after 30 mins of inactivity












0














After 30 mins of inactivity or so I start getting the below error when I try to insert into mongo, When I try again it starts to work. Error Below. I'm on Azure:



[INFO ] 2018-09-10T12:00:43,188 [http-nio-8080-exec-6] connection - Closed connection [connectionId{localValue:3, serverValue:26}] to XX.XX.XX.XX:27017 because there was a socket exception raised by this connection.
[ERROR] 2018-09-10T12:00:43,189 [http-nio-8080-exec-6] [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message] with root cause
java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_181]
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_181]
ava.net.SocketTimeoutException: Read timed out
t java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_181]
at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_181]


Here is how I initialize my mongo Template:



@Bean
public MongoDbFactory mongoDbFactory() {
String addresses = mongoUri.split(",");
List<ServerAddress> servers = new ArrayList<>();
for (String address : addresses) {
String split = address.trim().split(":");
servers.add(new ServerAddress(split[0].trim(), Integer.parseInt(split[1].trim())));
}
MongoClientOptions.Builder mongoOperations = MongoClientOptions.builder();
mongoOperations.socketTimeout(1000 * 20); // I tried to increase the socket timeout to see if it helps but no help either
mongoOperations.connectTimeout(1000 * 10);
MongoClient mongoClient = new MongoClient(servers, MongoCredential.createCredential(userName, dbName, password.toCharArray()), mongoOperations.build());
return new SimpleMongoDbFactory(mongoClient, dbName);
}

@Bean
public MongoTemplate getMongoTemplate() {
return new MongoTemplate(mongoDbFactory());
}


My mongod version is 3.6.4 and I'm using the same version of java driver.
I tried to increase/decrease the tcp_keepalive_time setting as provided in the docs using
sudo sysctl -w net.ipv4.tcp_keepalive_time=120 but no help either.










share|improve this question





























    0














    After 30 mins of inactivity or so I start getting the below error when I try to insert into mongo, When I try again it starts to work. Error Below. I'm on Azure:



    [INFO ] 2018-09-10T12:00:43,188 [http-nio-8080-exec-6] connection - Closed connection [connectionId{localValue:3, serverValue:26}] to XX.XX.XX.XX:27017 because there was a socket exception raised by this connection.
    [ERROR] 2018-09-10T12:00:43,189 [http-nio-8080-exec-6] [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message] with root cause
    java.net.SocketTimeoutException: Read timed out
    at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_181]
    at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_181]
    ava.net.SocketTimeoutException: Read timed out
    t java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_181]
    at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_181]


    Here is how I initialize my mongo Template:



    @Bean
    public MongoDbFactory mongoDbFactory() {
    String addresses = mongoUri.split(",");
    List<ServerAddress> servers = new ArrayList<>();
    for (String address : addresses) {
    String split = address.trim().split(":");
    servers.add(new ServerAddress(split[0].trim(), Integer.parseInt(split[1].trim())));
    }
    MongoClientOptions.Builder mongoOperations = MongoClientOptions.builder();
    mongoOperations.socketTimeout(1000 * 20); // I tried to increase the socket timeout to see if it helps but no help either
    mongoOperations.connectTimeout(1000 * 10);
    MongoClient mongoClient = new MongoClient(servers, MongoCredential.createCredential(userName, dbName, password.toCharArray()), mongoOperations.build());
    return new SimpleMongoDbFactory(mongoClient, dbName);
    }

    @Bean
    public MongoTemplate getMongoTemplate() {
    return new MongoTemplate(mongoDbFactory());
    }


    My mongod version is 3.6.4 and I'm using the same version of java driver.
    I tried to increase/decrease the tcp_keepalive_time setting as provided in the docs using
    sudo sysctl -w net.ipv4.tcp_keepalive_time=120 but no help either.










    share|improve this question



























      0












      0








      0







      After 30 mins of inactivity or so I start getting the below error when I try to insert into mongo, When I try again it starts to work. Error Below. I'm on Azure:



      [INFO ] 2018-09-10T12:00:43,188 [http-nio-8080-exec-6] connection - Closed connection [connectionId{localValue:3, serverValue:26}] to XX.XX.XX.XX:27017 because there was a socket exception raised by this connection.
      [ERROR] 2018-09-10T12:00:43,189 [http-nio-8080-exec-6] [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message] with root cause
      java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_181]
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_181]
      ava.net.SocketTimeoutException: Read timed out
      t java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_181]
      at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_181]


      Here is how I initialize my mongo Template:



      @Bean
      public MongoDbFactory mongoDbFactory() {
      String addresses = mongoUri.split(",");
      List<ServerAddress> servers = new ArrayList<>();
      for (String address : addresses) {
      String split = address.trim().split(":");
      servers.add(new ServerAddress(split[0].trim(), Integer.parseInt(split[1].trim())));
      }
      MongoClientOptions.Builder mongoOperations = MongoClientOptions.builder();
      mongoOperations.socketTimeout(1000 * 20); // I tried to increase the socket timeout to see if it helps but no help either
      mongoOperations.connectTimeout(1000 * 10);
      MongoClient mongoClient = new MongoClient(servers, MongoCredential.createCredential(userName, dbName, password.toCharArray()), mongoOperations.build());
      return new SimpleMongoDbFactory(mongoClient, dbName);
      }

      @Bean
      public MongoTemplate getMongoTemplate() {
      return new MongoTemplate(mongoDbFactory());
      }


      My mongod version is 3.6.4 and I'm using the same version of java driver.
      I tried to increase/decrease the tcp_keepalive_time setting as provided in the docs using
      sudo sysctl -w net.ipv4.tcp_keepalive_time=120 but no help either.










      share|improve this question















      After 30 mins of inactivity or so I start getting the below error when I try to insert into mongo, When I try again it starts to work. Error Below. I'm on Azure:



      [INFO ] 2018-09-10T12:00:43,188 [http-nio-8080-exec-6] connection - Closed connection [connectionId{localValue:3, serverValue:26}] to XX.XX.XX.XX:27017 because there was a socket exception raised by this connection.
      [ERROR] 2018-09-10T12:00:43,189 [http-nio-8080-exec-6] [dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Request processing failed; nested exception is org.springframework.data.mongodb.UncategorizedMongoDbException: Timeout while receiving message; nested exception is com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message] with root cause
      java.net.SocketTimeoutException: Read timed out
      at java.net.SocketInputStream.socketRead0(Native Method) ~[?:1.8.0_181]
      at java.net.SocketInputStream.socketRead(SocketInputStream.java:116) ~[?:1.8.0_181]
      ava.net.SocketTimeoutException: Read timed out
      t java.net.SocketInputStream.read(SocketInputStream.java:171) ~[?:1.8.0_181]
      at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_181]


      Here is how I initialize my mongo Template:



      @Bean
      public MongoDbFactory mongoDbFactory() {
      String addresses = mongoUri.split(",");
      List<ServerAddress> servers = new ArrayList<>();
      for (String address : addresses) {
      String split = address.trim().split(":");
      servers.add(new ServerAddress(split[0].trim(), Integer.parseInt(split[1].trim())));
      }
      MongoClientOptions.Builder mongoOperations = MongoClientOptions.builder();
      mongoOperations.socketTimeout(1000 * 20); // I tried to increase the socket timeout to see if it helps but no help either
      mongoOperations.connectTimeout(1000 * 10);
      MongoClient mongoClient = new MongoClient(servers, MongoCredential.createCredential(userName, dbName, password.toCharArray()), mongoOperations.build());
      return new SimpleMongoDbFactory(mongoClient, dbName);
      }

      @Bean
      public MongoTemplate getMongoTemplate() {
      return new MongoTemplate(mongoDbFactory());
      }


      My mongod version is 3.6.4 and I'm using the same version of java driver.
      I tried to increase/decrease the tcp_keepalive_time setting as provided in the docs using
      sudo sysctl -w net.ipv4.tcp_keepalive_time=120 but no help either.







      java mongodb azure spring-boot spring-data-mongodb






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 11 at 5:18

























      asked Sep 10 at 12:21









      Kid101

      870317




      870317
























          1 Answer
          1






          active

          oldest

          votes


















          0














          ohk. so we found that the mongo java driver jar was older than the mongo server we were using which was causing this issue. make sure that the driver supports the version of mongo server.






          share|improve this answer





















            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52257710%2fsocket-timeout-with-mongo-db-after-30-mins-of-inactivity%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            ohk. so we found that the mongo java driver jar was older than the mongo server we were using which was causing this issue. make sure that the driver supports the version of mongo server.






            share|improve this answer


























              0














              ohk. so we found that the mongo java driver jar was older than the mongo server we were using which was causing this issue. make sure that the driver supports the version of mongo server.






              share|improve this answer
























                0












                0








                0






                ohk. so we found that the mongo java driver jar was older than the mongo server we were using which was causing this issue. make sure that the driver supports the version of mongo server.






                share|improve this answer












                ohk. so we found that the mongo java driver jar was older than the mongo server we were using which was causing this issue. make sure that the driver supports the version of mongo server.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 13:15









                Kid101

                870317




                870317






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f52257710%2fsocket-timeout-with-mongo-db-after-30-mins-of-inactivity%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Schultheiß

                    Liste der Kulturdenkmale in Wilsdruff

                    Android Play Services Check