2

I have a spring boot applicaiton running which connects to mongoserver in azure cloud. The app continuesly gets java.net.SocketException: Connection reset exception for the first request after 4 secs idletime and fail. Then the subsequent requests are processed after a new connection is established.

Mongo client configuration

    @Bean
    public MongoClient mongoClient() {
        final String address = serverAddress;
        
        MongoCredential credential = MongoCredential.createCredential(userName, database, primaryPassword.toCharArray());
        ServerAddress sAddress = new ServerAddress(address, port);

        MongoClientOptions.Builder opBuilder = MongoClientOptions.builder();
        opBuilder.sslEnabled(true);
        opBuilder.requiredReplicaSetName(requiredReplicaSetName);
        opBuilder.maxConnectionIdleTime(1500000);
        opBuilder.socketTimeout(30000);
        opBuilder.connectTimeout(30000);

        // MongoClient
        return new MongoClient(sAddress, credential, opBuilder.build());
    }

and the exception:

    2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT Caused by: org.springframework.data.mongodb.UncategorizedMongoDbException: Exception sending message; nested exception is com.mongodb.MongoSocketWriteException: Exception sending message
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT     
at org.springframework.data.mongodb.repository.query.AbstractMongoQuery.lambda$getExecution$1(AbstractMongoQuery.java:115) ~[spring-data-mongodb-2.1.14.RELEASE.jar!/:2.1.14.RELEASE]
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT     at 
        ... 98 common frames omitted
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT Caused by: com.mongodb.MongoSocketWriteException: Exception sending message
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT     at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:525) ~[mongo-java-driver-3.8.2.jar!/:na]
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT     ... 130 common frames omitted
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT Caused by: java.net.SocketException: Connection reset
       2020-08-05T11:40:55.34-0400 [APP/PROC/WEB/0] OUT     ... 152 common frames omitted

I tried changing the connection timeout, socketimeout and maxConnectionIdleTime to increase/decrese but the app continuesly gets this exception after 4sec of idle time.

4
  • I think you need to decrease keepalive interval in your system tcp settings. Commented Aug 5, 2020 at 19:21
  • To something like 100 seconds. Commented Aug 5, 2020 at 19:21
  • SPring boot app is running in PCF cloud. How do I set it and could you explain the reason you believe that is causing the issue Commented Aug 5, 2020 at 19:42
  • I suggest you research that on your own. Commented Aug 5, 2020 at 19:46

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.