MongoDB 连接突然停止工作
Posted
技术标签:
【中文标题】MongoDB 连接突然停止工作【英文标题】:MongoDB connection suddenly stopped working 【发布时间】:2021-03-20 07:58:00 【问题描述】:我有一个连接到在 Heroku 上运行的 MongoDB 的 Spring Boot 应用程序,直到几天前它都没有问题。我没有更改代码或任何地方的任何内容。在本地,我有相同的构建,这在 heroku 上都很好。
Stacktrace如下
Exception in monitor thread while connecting to server <collectionname>-shard-00-00.dhetx.mongodb.net:27017
com.mongodb.MongoSocketWriteException: Exception sending message
at com.mongodb.internal.connection.InternalStreamConnection.translateWriteException(InternalStreamConnection.java:550) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:432) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendCommandMessage(InternalStreamConnection.java:272) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:256) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:103) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:60) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-4.0.5.jar:na]
at java.base/java.lang.Thread.run(Thread.java:830) ~[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:311) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:267) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258) ~[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:396) ~[na:na]
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:444) ~[na:na]
at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:422) ~[na:na]
at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:181) ~[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:1460) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1368) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:437) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.ensureNegotiated(SSLSocketImpl.java:878) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl$AppOutputStream.write(SSLSocketImpl.java:1240) ~[na:na]
at com.mongodb.internal.connection.SocketStream.write(SocketStream.java:99) ~[mongodb-driver-core-4.0.5.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendMessage(InternalStreamConnection.java:429) ~[mongodb-driver-core-4.0.5.jar:na]
... 9 common frames omitted
和 application.properties
server.port=$PORT:8080
spring.data.mongodb.uri=mongodb+srv://<login>:<pasword>@<collectionname>.dhetx.mongodb.net/<collectionname>?retryWrites=true&w=majority
spring.data.mongodb.database=<collectionname>
logging.level.org.atmosphere = warn
spring.mustache.check-template-location = false
感谢 0.0.0.0/0,我将所有 IP 都列入了 Atlas 的白名单,所以可能不是这样(而且它以前一直有效)。
有没有人遇到过类似的问题?我不知道该怎么做。感谢任何答案。
【问题讨论】:
我确实发现了类似的问题Spring Boot MongoDB Connectivity Issue希望对您有所帮助! 升级到 jdk 14.0.2 对我有帮助。谢谢你的回答! 【参考方案1】:这似乎是 OpenJDK 中的一个错误。
有同样的问题。我的应用在 AWS 上运行,但不是在我的本地机器上运行。
我将我的开发 JDK 从 OpenJDK 更改为 Corretto,问题就解决了。
让我知道这是否也适合你
【讨论】:
升级到 jdk 14.0.2 对我有帮助。谢谢你的回答!以上是关于MongoDB 连接突然停止工作的主要内容,如果未能解决你的问题,请参考以下文章
以前部署到 Heroku 时可以工作的 KeystoneJS V4 应用程序现在停止工作 - MongoDB Atlas