0

I have following problem:
1. I have setup spring boot app which uses MongoDB database.
2. I tested it locally and it works - app connects to database properly.
3. I deployed spring boot app to azure, but app cannot connect to MongoDB database. I get below exception:

"Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers= [{address=appexpirer.documents.azure.com:10250, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message}, caused by {java.net.SocketTimeoutException: Read timed out}}]; nested exception is com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches ReadPreferenceServerSelector{readPreference=primary}. Client view of cluster state is {type=UNKNOWN, servers= [{address=appexpirer.documents.azure.com:10250, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketReadTimeoutException: Timeout while receiving message}, caused by {java.net.SocketTimeoutException: Read timed out}}]"

I believe that my application.properties are properly configured:

spring.data.mongodb.uri=mongodb://username:password@host:port/databaseName?ssl=true&sslInvalidHostNameAllowed=true
server.ssl.enabled=true
server.ssl.enabled-protocols=true

but I am not sure of that - could you please advice me what is wrong?

If I connect with using Robomongo tool everyting works well. I use Java 8 - can it be problem?

6
  • How was the boot app deployed to azure? Is there anything that might be preventing outbound access to your DocumentDb endpoint? Commented Mar 10, 2017 at 17:59
  • I deployed app.jar file and web.config file via git. I wonder if it can be problem with ssl, because I have no ssl configured on app service on Azure and MongoDB requires SSL connection - have you ever met with such case? Commented Mar 11, 2017 at 5:54
  • I can hit mongo endpoint your error shows from a boot up from my machine. It shows authentication error (obviosly), so it seems like the the connectivity issue is not to the mongo endpoint, but rather from where your boot app lives. Commented Mar 11, 2017 at 12:22
  • I believe that azure app service need ssl certificate to communicate with mongodb, since the only way is to use ssl to connect to mongodb - I will try to investigate it more. Commented Mar 13, 2017 at 12:03
  • Finally I have solved it. The problem was really stupid. When I upload app.jar file via git app was in fact not updated on Azure. I noticed that there was exception which indicated that app cannot be updated, because previous version is running... I had to stop process manually, upload new version and then run uploaded version manually. Anyway thank you all for help. Commented Mar 13, 2017 at 16:34

2 Answers 2

0

Did you open up the connection from your app server to the database(Mongo) server? That error sounds like a firewall just dropping the request packets.

Services like Azure and AWS have everything locked down pretty tightly. You generally have to explicitly open up or allow every connection point you want to use.

Sign up to request clarification or add additional context in comments.

1 Comment

What do you mean - "Did you open up the connection from your app server to the database(Mongo) server"? I have setup app service and database server. Both are setup and hosted on Azure. Should I somehow setup connection between those two on Azure? I can connect to database from Robomongo, but not from app service (always get timestamp).
0

I had the similar problem for the Spring boot services deployed on AWS Beanstalk. The problem was occurring because I deployed new version and the old versions were still running on ECS.

I had to manually terminate the environment and deploy newly the services. IT resolved the issue. Only re-deployment without termination, does not help. Make sure to configure your Host / Domain to ELB again after new deployment.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.