I\'ve a Java application that performs some aggregations on MongoDB, but sometimes it just hangs and throw a SocketTimeout exception. After the Exception the app will run ju
After few tries I've found out that it was a problem with the Azure's Load Balancer.
After 60s of inactivity it will disconnect any pending TCP connection.
After further digging I've found this post of the MongoDB diagnostics FAQ, and I've set the tcp keepalive to 120s:
sudo sysctl -w net.ipv4.tcp_keepalive_time=
and I've also set the socketKeepAlive of the MongoClient to true:
MongoClientOptions.Builder options = MongoClientOptions.builder();
options.socketKeepAlive(true);
mongoClient = new MongoClient(mongoAddress, options.build());
After these fixes the issue seems gone!