Spring Boot MongoDB Connectivity Issue
Asked Answered
P

7

16

My Spring Boot application is trying to connect to MongoDB Database. The configuration is added on application.yml file. The application was working completely fine locally till yesterday.

But when today I am running it locally on localhost, the following error I am receiving:

2020-12-03 14:59:03.763[0;39m [32m INFO[0;39m [35m10692[0;39m [2m---[0;39m [2m[ngodb.net:27017][0;39m [36morg.mongodb.driver.cluster              [0;39m [2m:[0;39m Exception in monitor thread while connecting to server edugyanamcluster-shard-00-00.l4au7.mongodb.net:27017

com.mongodb.MongoSocketWriteException: Exception sending message
    at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:551) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:433) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:273) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:257) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:105) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:62) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:129) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-3.11.2.jar:na]
    at java.base/java.lang.Thread.run(Thread.java:835) ~[na:na]
Caused by: javax.net.ssl.SSLHandshakeException: extension (5) should not be presented in certificate_request
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131) ~[na:na]
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:117) ~[na:na]
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:307) ~[na:na]
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263) ~[na:na]
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:254) ~[na:na]
    at java.base/sun.security.ssl.SSLExtensions.<init>(SSLExtensions.java:90) ~[na:na]
    at java.base/sun.security.ssl.CertificateRequest$T13CertificateRequestMessage.<init>(CertificateRequest.java:818) ~[na:na]
    at java.base/sun.security.ssl.CertificateRequest$T13CertificateRequestConsumer.consume(CertificateRequest.java:922) ~[na:na]
    at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:392) ~[na:na]
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:443) ~[na:na]
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:421) ~[na:na]
    at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:177) ~[na:na]
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:164) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1180) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1091) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:721) ~[na:na]
    at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:998) ~[na:na]
    at com.mongodb.internal.connection.SocketStream.write(SocketStream.java:99) ~[mongodb-driver-core-3.11.2.jar:na]
    at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:430) ~[mongodb-driver-core-3.11.2.jar:na]
    ... 9 common frames omitted

[2m2020-12-03 14:59:05.112[0;39m [33m WARN[0;39m [35m10692[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mJpaBaseConfiguration$JpaWebConfiguration[0;39m [2m:[0;39m spring.jpa.open-in-view is enabled by default. Therefore, database queries may be performed during view rendering. Explicitly configure spring.jpa.open-in-view to disable this warning
[2m2020-12-03 14:59:07.468[0;39m [32m INFO[0;39m [35m10692[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36mpertySourcedRequestMappingHandlerMapping[0;39m [2m:[0;39m Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2ControllerWebMvc#getDocumentation(String, HttpServletRequest)]
[2m2020-12-03 14:59:07.822[0;39m [32m INFO[0;39m [35m10692[0;39m [2m---[0;39m [2m[  restartedMain][0;39m [36m.s.s.UserDetailsServiceAutoConfiguration[0;39m [2m:[0;39m

Need advice on what is the issue all about? As the code was working completely fine few hours before.

Pals answered 3/12, 2020 at 11:55 Comment(2)
We're starting to see the exact same issue today. Are yours from Atlas?Namely
Yes, this issue is coming from today itself. MongoDB has updated their server actually, might have updated their cipher. The solution is actually change the TLS Version to 1.2 in JVM params. You can add in Eclipse -> Project -> Run As -> Run Configurations -> Arguments -> VM Arguments (add -> -Djdk.tls.client.protocols=TLSv1.2).Pals
P
18

MongoDB has updated their server actually, might have updated their cipher. The solution is actually change the TLS Version to 1.2 in JVM params.

One can add in Eclipse (if using it as an IDE) -> Project -> Run As -> Run Configurations -> Arguments -> VM Arguments, add ->

-Djdk.tls.client.protocols=TLSv1.2
Pals answered 11/12, 2020 at 9:38 Comment(0)
M
14

I could fix this issue using the solution from this other question. I changed the TLS version to 1.2 in JVM params:

-Djdk.tls.client.protocols=TLSv1.2
Marla answered 3/12, 2020 at 15:20 Comment(5)
Thanks. Where can I add the JVM params? Can you pls guide?Pals
If you could clarify how you would add this option to a Maven pom.xml, I'd be really grateful!Sarmatia
It's just an execution parameter: java -Djdk.tls.client.protocols=TLSv1.2 -jar app.jarMarla
Thanks for saving a crisis you should be paid for this, wondering how easy it is for Mongo folks to break things as per their convenienceBreeden
Thanks for the solution, it worked. Is there any info on what caused this bug and until when we have to use this workaround?Theomancy
N
5

Other than downgrading to TLSV1.2, Upgrading your JDK fixes this too.

For JDK version 11.0.0 - 11.0.6, upgrading your JDK to a patched version. JDK-8236039

JDK version 13.0.0 - 13.0.02, upgrading to 13.0.03 should resolve this issue JDK-8241515

Namely answered 3/12, 2020 at 17:54 Comment(3)
updating from 14.0.1 to 14.0.2 has also worked for meCertes
I'm running Amazon Corretto JDK version 11.0.9.1+12-LTS and still seeing this error.Slavonic
Version 15 showing the same error, but only for some of our developers. Very frustrating.Slavonic
C
1

I had literally tried everything like upgrading the jdk and all but the best solution and also the working one is changing the TLS version.

Right click on the project in IDE Run As -> Run Configurations... And goto Arguments tab and in VM Arguments add this -Djdk.tls.client.protocols=TLSv1.2

Run the application now and it should work fine.

You can refer for images attached for more clarity.

enter image description here

enter image description here

Cultivator answered 10/12, 2020 at 15:24 Comment(0)
S
1

I updated from JDK 11.0.7 to 11.0.10 and now it works

Selfaddressed answered 11/4, 2021 at 2:20 Comment(0)
K
1

I had this problem and solved first adding this parameter to the JVM:

-Djdk.tls.client.protocols=TLSv1.2

But later, I changed the openjdk:12 docker image to the latest openjdk:11 (LTS) and it solved the issue without the -D parameter anymore =)

Kallick answered 1/4, 2022 at 20:9 Comment(0)
B
0

I had the same issue https://bugs.openjdk.java.net/browse/JDK-8236039 and I change my JDK to JDK-15 zulu: https://www.azul.com/downloads/zulu-community/?version=java-15-mts and it fixed the problem, I was previously using a version of Open JDK.

Bandwagon answered 12/2, 2021 at 4:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.