'Exception in monitor thread while connecting to server <xyz> using mongo-driver-core-4.1.2 jar
I have upgraded mongo java driver <mongodb.version>3.12.8</mongodb.version> to mongodb-driver-legacy 4.1.2. since then when ever i am trying to up the application in SIT getting below error .if i downgrade the version it works fine but with this version it throwing exception .
apart from mongo java driver , spring-data-mongodb is of 1.10.18 version and mongodb-driver-core is of 4.1.2 version.
This is my code to create mongoclient.
private MongoClientURI getClient(String uri, final boolean isCyberArkEnabled,
final String cyberArkNickname, final String cyberArkAppID, final String cyberArkSafe,
final String cyberArkObject, TrustManager[] byPassTrustManagers, InputStream targetStream)
throws Exception {
MongoClientURI uriObj = null;
final int maxConnections = 100;
MongoClientOptions.Builder options;
try {
options = new MongoClientOptions.Builder().socketTimeout(getMongoSocketTimeout())
// MongoSSLSocketFactory accepts self-signed certificate
.sslContext(createSSLContext(byPassTrustManagers, targetStream))
.sslInvalidHostNameAllowed(false).connectionsPerHost(maxConnections);
log.info("MongoURI before decoding:{}", uri);
uri = decodeMongoPassword(uri, isCyberArkEnabled, cyberArkNickname, cyberArkAppID, cyberArkSafe,
cyberArkObject);
log.info("MongoURI after decoding:{}", uri);
uriObj = new MongoClientURI(uri, options);
} catch (MongoException ex) {
log.error("Exception while instantiating mongo client");
}
return uriObj;
}
private SSLContext createSSLContext (TrustManager[] byPassTrustManagers, InputStream targetStream)
throws Exception {
final String protocol = CoreModule.getConfiguration().getString("TLSv1.2");
SSLContext sslContext = SSLContext.getInstance(protocol);
sslContext.init(null, byPassTrustManagers, new SecureRandom());
targetStream.close();
return sslContext;}
Error -
2022-05-13 10:01:30 INFO [cluster-ClusterId{value='627e64bac2dd3e1960e5ca66', description='null'}-maas-gtz-p05-m0005.nam.nsroot.net:37017] [org.mongodb.driver.cluster] - Exception in monitor thread while connecting to server maas-gtz-p05-m0005.nam.nsroot.net:37017
com.mongodb.MongoSocketReadException: Prematurely reached end of stream
at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:112) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.SocketStream.read(SocketStream.java:131) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:648) ~[mongodb-driver-core-4.1.2.jar:?]
at
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessageWithAdditionalTimeout(InternalStreamConnection.java:513) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:356) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:280) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:107) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:144) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:188) ~[mongodb-driver-core-4.1.2.jar:?]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:144) ~[mongodb-driver-core-4.1.2.jar:?]
at java.lang.Thread.run(Thread.java:834) [?:?]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|