Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MongoDb Srv connection does not work on windows #28607

Closed
Liuigi opened this issue Oct 14, 2022 · 5 comments · Fixed by #28608
Closed

MongoDb Srv connection does not work on windows #28607

Liuigi opened this issue Oct 14, 2022 · 5 comments · Fixed by #28608
Labels
area/mongodb env/windows Impacts Windows machines kind/bug Something isn't working
Milestone

Comments

@Liuigi
Copy link
Contributor

Liuigi commented Oct 14, 2022

Describe the bug

For the windows project, when you run the application with the maven commande
mvn compile quarkus:dev -Dquarkus.profile=local

The application failed to open a mongo connection with the SRV protocol.
"/etc/resolv.conf"

Expected behavior

The mongodb SRV protocol should work out of the box

Actual behavior

we have a great stack trace with NPE :

2022-10-14 18:17:06,767 ERROR [org.jbo.res.rea.com.cor.AbstractResteasyReactiveContext] (executor-thread-0) Request failed: java.lang.NullPointerException: Cannot invoke "java.util.List.isEmpty()" because "list" is null
	at io.quarkus.mongodb.runtime.dns.MongoDnsClient.lambda$new$0(MongoDnsClient.java:58)
	at java.base/java.util.Optional.orElseGet(Optional.java:364)
	at io.quarkus.mongodb.runtime.dns.MongoDnsClient.<init>(MongoDnsClient.java:56)
	at io.quarkus.mongodb.runtime.dns.MongoDnsClientProvider.create(MongoDnsClientProvider.java:12)
	at com.mongodb.internal.dns.DefaultDnsResolver.<init>(DefaultDnsResolver.java:44)
	at com.mongodb.ConnectionString.<init>(ConnectionString.java:397)
	at io.quarkus.mongodb.runtime.MongoClients.createMongoConfiguration(MongoClients.java:262)
	at io.quarkus.mongodb.runtime.MongoClients.createMongoClient(MongoClients.java:118)
	at io.quarkus.mongodb.runtime.MongoClients_Subclass.createMongoClient$$superforward1(Unknown Source)
	at io.quarkus.mongodb.runtime.MongoClients_Subclass$$function$$4.apply(Unknown Source)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:53)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:62)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
	at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(Unknown Source)
	at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
	at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:40)
	at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
	at io.quarkus.mongodb.runtime.MongoClients_Subclass.createMongoClient(Unknown Source)
	at io.quarkus.mongodb.runtime.MongoClientRecorder.lambda$mongoClientSupplier$0(MongoClientRecorder.java:63)
	at io.quarkus.mongodb.runtime.MongoClientRecorder$MongoClientSupplier.get(MongoClientRecorder.java:57)
	at com.mongodb.client.MongoClient_38bcba43bbcf7928744e8baa654420f551f1ff9a_Synthetic_Bean.create(Unknown Source)
	at com.mongodb.client.MongoClient_38bcba43bbcf7928744e8baa654420f551f1ff9a_Synthetic_Bean.create(Unknown Source)
	at io.quarkus.arc.impl.AbstractSharedContext.createInstanceHandle(AbstractSharedContext.java:111)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:35)
	at io.quarkus.arc.impl.AbstractSharedContext$1.get(AbstractSharedContext.java:32)
	at io.quarkus.arc.impl.LazyValue.get(LazyValue.java:26)
	at io.quarkus.arc.impl.ComputingCache.computeIfAbsent(ComputingCache.java:69)
	at io.quarkus.arc.impl.AbstractSharedContext.get(AbstractSharedContext.java:32)
	at io.quarkus.arc.impl.ClientProxies.getApplicationScopedDelegate(ClientProxies.java:19)
	at com.mongodb.client.MongoClient_38bcba43bbcf7928744e8baa654420f551f1ff9a_Synthetic_ClientProxy.arc$delegate(Unknown Source)
	at com.mongodb.client.MongoClient_38bcba43bbcf7928744e8baa654420f551f1ff9a_Synthetic_ClientProxy.getDatabase(Unknown Source)

How to Reproduce?

Step to reproduce the behaviour :

  1. Having a windows environment or not having the right to read this file ( "/etc/resolv.conf")
  2. try to connect a mongodb with srv protocole ( url connection must start with mongodb+srv)
  3. try to open the connection, the NPE rise !

Output of uname -a or ver

No response

Output of java -version

Java version: 17.0.1

GraalVM version (if different from Java)

No response

Quarkus version or git rev

2.12.0

Build tool (ie. output of mvnw --version or gradlew --version)

Apache Maven 3.8.1

Additional information

You should not initialize a list with null

List nameServers = null;

should be nameServers = new ArrayList<>();

@Liuigi Liuigi added the kind/bug Something isn't working label Oct 14, 2022
@quarkus-bot quarkus-bot bot added area/mongodb env/windows Impacts Windows machines labels Oct 14, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Oct 14, 2022

/cc @evanchooly, @loicmathieu

@nicoDs96
Copy link

Hi, I had the same issue today, a workaround is using legacy connection string specifing shards, like mongodb://<usr>:<psw>@<cluster_id>.mongodb.net:27017,<cluster_id>-shard-00-01.ysvl5.mongodb.net:27017,<cluster_id>-shard-00-02.ysvl5.mongodb.net:27017/?ssl=true&replicaSet=atlas-j022j2-shard-0&authSource=admin&retryWrites=true&w=majority.

My application.properties:

# configure the MongoDB client for a replica set of two nodes
quarkus.mongodb.connection-string=mongodb://<usr>:<psw>@<cluster_id>.mongodb.net:27017,<cluster_id>-shard-00-01.ysvl5.mongodb.net:27017,<cluster_id>-shard-00-02.ysvl5.mongodb.net:27017/?ssl=true&replicaSet=atlas-j022j2-shard-0&authSource=admin&retryWrites=true&w=majority
# mandatory if you don't specify the name of the database using @MongoEntity
quarkus.mongodb.database = Feeds

@geoand
Copy link
Contributor

geoand commented Oct 17, 2022

Can you try with Quarkus 2.13.2.Final please?

If the problem still persists, please attach a sample project that exhibits the problematic behavior.

@Liuigi
Copy link
Contributor Author

Liuigi commented Oct 17, 2022

@nicoDs96 juste create an empty file "/etc/resolv.conf" and it will work ;)
@geoand i accept your review, it will nice if the fix is deployed soon

@geoand
Copy link
Contributor

geoand commented Oct 17, 2022

That should likely happen with 2.13.3.Final, likely within the next 7 to 10 days

@quarkus-bot quarkus-bot bot added this to the 2.14 - main milestone Oct 18, 2022
@gsmet gsmet modified the milestones: 2.14 - main, 2.13.3.Final Oct 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/mongodb env/windows Impacts Windows machines kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants