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.