简体   繁体   English

MongoDB Atlas Java 驱动程序 TLS 问题

[英]MongoDB Atlas Java Driver TLS Issue

I have a Java based server running in Docker using openjdk:15-jdk-alpine.我有一个基于 Java 的服务器,使用 openjdk:15-jdk-alpine 在 Docker 中运行。 It connects to MongoDB Atlas using the mongodb-driver-reactivestreams driver.它使用 mongodb-driver-reactivestreams 驱动程序连接到 MongoDB Atlas。 Similarly I have a second SpringBoot based server running in Docker that connects using the same credentials and runs just fine.同样,我有第二个基于 SpringBoot 的服务器在 Docker 中运行,它使用相同的凭据进行连接并且运行良好。

When I run my code in in IntelliJ it runs without errors, connects to MongoDB and I can query, insert documents ect...当我在 IntelliJ 中运行我的代码时,它运行没有错误,连接到 MongoDB,我可以查询、插入文档等...

When I put it in a Docker container and spin up the server, I get the following error message: Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.internal.connection.tlschannel.TlsChannel When I put it in a Docker container and spin up the server, I get the following error message: Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.internal.connection.tlschannel.TlsChannel

When I disable tls using tls=false in the connection string I get the message MongoSocketReadException: Prematurely reached end of stream .当我在连接字符串中使用tls=false禁用 tls 时,我收到消息MongoSocketReadException: Prematurely reached end of stream

In both instances, when looking through the log I can see that the server was able to identify all the shards in my MongoDB cluster, so it is connecting to Mongo Atlas and receiving information back.在这两种情况下,当查看日志时,我可以看到服务器能够识别我的 MongoDB 集群中的所有分片,因此它正在连接到 Mongo Atlas 并接收回信息。

My current theory is that 1) Tls is required to connect 2) Tls is not working in my docker container for some reason to do with the JVM key store/truststore.我目前的理论是 1) Tls 需要连接 2) Tls 在我的 docker 容器中由于某种原因与 JVM 密钥库/信任库有关。

I dont know enough about TLS or Java key store stuff to debug this, and dont know what to search to get to an answer.我对 TLS 或 Java 密钥库的东西了解不够,无法调试它,也不知道要搜索什么才能得到答案。 If anyone can point me in the right direction it will be much appreciated...如果有人能指出我正确的方向,将不胜感激......

2021-10-14 17:58:53.730 DEBUG c608e84d3bb5 --- [           main] u.s.PropertiesServiceImpl : Looking for profiles.

2021-10-14 17:58:53.734  INFO c608e84d3bb5 --- [           main] u.s.PropertiesServiceImpl : Profile found: dev

2021-10-14 17:58:53.773 DEBUG c608e84d3bb5 --- [           main] c.p.s.c.SocketAcceptor    : Creating server Socket at port: 6666

2021-10-14 17:58:53.788 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Connecting to Redis: localhost/6379

2021-10-14 17:58:53.872 DEBUG c608e84d3bb5 --- [           main] r.u.Loggers               : Using Slf4j logging framework

2021-10-14 17:58:54.249 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:54.764 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:55.273 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:55.783 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:56.298 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:56.810 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:57.322 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:57.834 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:58.347 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:58.857 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection failed, retrying...

2021-10-14 17:58:59.358 DEBUG c608e84d3bb5 --- [           main] s.r.s.RedisConnectionImpl : Redis connection could not be established!

2021-10-14 17:58:59.554 DEBUG c608e84d3bb5 --- [           main] .s.r.s.GameControllerImpl : Starting Room Manager

2021-10-14 17:58:59.646  INFO c608e84d3bb5 --- [           main] c.p.s.m.s.MongoDB         : Mongodb target is: mongodb+srv://XXXXX:XXXXX@XXXXXX.erble.gcp.mongodb.net/xxxxxxx?retryWrites=true&w=majority

2021-10-14 17:58:59.667 DEBUG c608e84d3bb5 --- [           main] c.p.s.m.s.MongoDB         : Starting MongoDb database...

2021-10-14 17:58:59.680  INFO c608e84d3bb5 --- [           main] o.m.d.cluster             : Cluster created with settings {hosts=[127.0.0.1:27017], srvHost=XXXXXX.erble.gcp.mongodb.net, mode=MULTIPLE, requiredClusterType=REPLICA_SET, serverSelectionTimeout='30000 ms', requiredReplicaSetName='XXXXXX-shard-0'}

2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [           main] c.p.s.m.s.MongoDB         : MongoDb client initialised.

2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [           main] c.p.s.m.s.MongoDB         : MongoDb client initialised.

2021-10-14 17:58:59.699 DEBUG c608e84d3bb5 --- [           main] c.p.s.Application         : Starting server...

2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [ AcceptorThread] c.p.s.c.SocketAcceptor    : Starting Socket acceptor loop...

2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [ProcessorThread] c.p.s.c.SocketProcessor   : Starting Socket processor loop...

2021-10-14 17:58:59.700 DEBUG c608e84d3bb5 --- [   ReaderThread] c.p.s.c.SocketReader      : Starting Socket reader loop...

2021-10-14 17:58:59.701 DEBUG c608e84d3bb5 --- [   WriterThread] c.p.s.c.SocketWriter      : Starting Socket writer loop...

2021-10-14 17:58:59.702 DEBUG c608e84d3bb5 --- [       Thread-5] c.p.s.c.MessageReceiver   : Starting loop.

2021-10-14 17:58:59.702 DEBUG c608e84d3bb5 --- [           main] c.p.s.m.s.MongoDB         : MongoDb client initialised.

2021-10-14 17:58:59.744  INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster             : Adding discovered server XXXXXX-shard-00-01.erble.gcp.mongodb.net:27017 to client view of cluster

2021-10-14 17:58:59.766  INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster             : Adding discovered server XXXXXX-shard-00-02.erble.gcp.mongodb.net:27017 to client view of cluster

2021-10-14 17:58:59.768  INFO c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster             : Adding discovered server XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017 to client view of cluster

2021-10-14 17:58:59.770 DEBUG c608e84d3bb5 --- [gcp.mongodb.net] o.m.d.cluster             : Updating cluster description to  {type=REPLICA_SET, servers=[{address=XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=XXXXXX-shard-00-01.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}, {address=XXXXXX-shard-00-02.erble.gcp.mongodb.net:27017, type=UNKNOWN, state=CONNECTING}]

2021-10-14 17:59:00.093 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:6}

2021-10-14 17:59:00.093 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:2}

2021-10-14 17:59:00.094 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:5}

2021-10-14 17:59:00.095 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:3}

2021-10-14 17:59:00.095 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:1}

2021-10-14 17:59:00.096 DEBUG c608e84d3bb5 --- [ngodb.net:27017] o.m.d.connection          : Closing connection connectionId{localValue:4}

2021-10-14 17:59:00.095  INFO c608e84d3bb5 --- [ngodb.net:27017] o.m.d.cluster             : Exception in monitor thread while connecting to server XXXXXX-shard-00-00.erble.gcp.mongodb.net:27017

com.mongodb.MongoInternalException: Opening the TlsChannelStream failed

at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.get(AsynchronousChannelStream.java:328)

at com.mongodb.internal.connection.AsynchronousChannelStream$FutureAsyncCompletionHandler.getOpen(AsynchronousChannelStream.java:304)

at com.mongodb.internal.connection.AsynchronousChannelStream.open(AsynchronousChannelStream.java:125)

at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:165)

at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.lookupServerDescription(DefaultServerMonitor.java:195)

at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:151)

at java.base/java.lang.Thread.run(Thread.java:832)

Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.internal.connection.tlschannel.TlsChannel

at com.mongodb.internal.connection.tlschannel.TlsChannelBuilder.<init>(TlsChannelBuilder.java:37)

at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:45)

at com.mongodb.internal.connection.tlschannel.ClientTlsChannel$Builder.<init>(ClientTlsChannel.java:40)

at com.mongodb.internal.connection.tlschannel.ClientTlsChannel.newBuilder(ClientTlsChannel.java:87)

at com.mongodb.connection.TlsChannelStreamFactoryFactory$TlsChannelStream.lambda$openAsync$0(TlsChannelStreamFactoryFactory.java:236)

at com.mongodb.connection.TlsChannelStreamFactoryFactory$SelectorMonitor.lambda$start$0(TlsChannelStreamFactoryFactory.java:141)

... 1 more

This issue is very likely to be connected with this (already fixed) bug https://jira.mongodb.org/browse/JAVA-4656 (driver fails to parse java.version property if it contains only dashes and no dots, 15 , 15.0.1 or 15.0.1-something works fine, but 15-whatever fails) This issue is very likely to be connected with this (already fixed) bug https://jira.mongodb.org/browse/JAVA-4656 (driver fails to parse java.version property if it contains only dashes and no dots, 15 , 15.0.115.0.1-something工作正常,但15-whatever失败)

So the solution is to update your mongo driver to the latest version or maybe to update your java version to version with some dots所以解决方案是将您的 mongo 驱动程序更新到最新版本,或者将您的 java 版本更新为带有一些点的版本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM