MongoCommandException: Command failed with error 8000 (AtlasError): 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.'

强颜欢笑 提交于 2020-06-13 05:34:08

问题


I'm using Java 11 (Maven project) for mongodb Free Tier Cluster (Version 4.0.13). I'm trying to connect via connection-string (for 3.6 drivers or later) like:

mongodb+srv://user:pass@cluster0-ox90k.mongodb.net/test?retryWrites=true&w=majority

and by the same way via connection-string (for 3.4 driver or later):

mongodb://user:pass@cluster0-shard-00-00-ox90k.mongodb.net:27017,cluster0-shard-00-01-ox90k.mongodb.net:27017,cluster0-shard-00-02-ox90k.mongodb.net:27017/test?ssl=true&replicaSet=Cluster0-shard-0&authSource=admin&retryWrites=true&w=majority

I've already tested different dependencies for java drivers like: mongodb-driver-sync (ver. 3.11.0), mongodb-driver-sync (ver. 3.10.0) , mongodb-driver-sync (ver. 3.8.0).

Maven dependency looks like this:

 <dependency>
      <groupId>org.mongodb</groupId>
      <artifactId>mongodb-driver-sync</artifactId>
      <version>3.11.0</version>
 </dependency>

Also I tried to use mongo-java-driver via connection-string for 3.6 or later drivers/3.4 or later and versions like: 3.11.0, 3.10.0, 3.8.0, 3.7.0.

Maven dependency looks like this:

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.11.0</version>
</dependency>

And I'm getting always the same issue:

Exception in thread "main" com.mongodb.MongoCommandException: Command failed with error 8000: 'no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.' on server cluster0-shard-00-01-ox90k.mongodb.net:27017. The full response is { "ok" : 0, "errmsg" : "no SNI name sent, make sure using a MongoDB 3.4+ driver/shell.", "code" : 8000, "codeName" : "AtlasError" }
    at com.mongodb.connection.ProtocolHelper.getCommandFailureException(ProtocolHelper.java:164)
    at com.mongodb.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:286)
    at com.mongodb.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:247)
    at com.mongodb.connection.CommandHelper.sendAndReceive(CommandHelper.java:84)
    at com.mongodb.connection.CommandHelper.executeCommand(CommandHelper.java:34)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:91)
    at com.mongodb.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:51)

My current POM is:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>test</groupId>
    <artifactId>test_project</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
        </dependency>
        <dependency>
            <!-- jsoup HTML parser library @ https://jsoup.org/ -->
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.3</version>
        </dependency>
        <dependency>
            <groupId>org.mongodb</groupId>
            <artifactId>mongo-java-driver</artifactId>
            <version>3.11.0</version>
        </dependency>   
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>3.1.0</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>    
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>    
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>project.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Any ideas how to solve the issue will be appreciated.


回答1:


I had the same issue using a Docker image from adoptopenjdk/openjdk11-openj9:jdk-11.0.1.13-alpine-slim. Since I've upgraded to adoptopenjdk/openjdk11-openj9:jdk-11.0.5.10-alpine-slim, my connection to MongoDB is OK.




回答2:


Java 8

I've changed Java 11 to Java 8 and it solved the issue. Looks like Java 11 doesn't support SNI. Because all attempts were unsuccessful despite the fact that I used the latest drivers.

Java 11

Thanks to clarification by Virg, I've changed version of Java 11, but also the license. I had Java 11 using Java Development Kit builds (from Oracle) - as sourse. Then I've installed another license as Azulu using JDK version 11.0.5+10 and it also solved the error.



来源:https://stackoverflow.com/questions/59112124/mongocommandexception-command-failed-with-error-8000-atlaserror-no-sni-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!