[JAVA-2161] com.mongodb.MongoSocketOpenException: Exception opening socket Created: 31/Mar/16  Updated: 11/Sep/19  Resolved: 01/Apr/16

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: 3.2.2
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Junwei Zhuge Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac osX, Heroku



 Description   

I want to build a web application on Heroku, I can connect to mongodb, because I tried to create a collection in the Main.java, and it worked.
There is the error message:

6:47:08 PM web.1 |  [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[ds015869.mlab.com:15869], mode=SINGLE, requiredClusterTy…
6:47:08 PM web.1 |  [main] INFO org.mongodb.driver.cluster - Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNO…
6:47:08 PM web.1 |  [cluster-ClusterId{value='56fda8ece1a1e38897e615c5', description='null'}-127.0.0.1:27017] INFO org.mongodb.driver.cluster - Exception i…
6:47:08 PM web.1 |  com.mongodb.MongoSocketOpenException: Exception opening socket
6:47:08 PM web.1 |  	at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
6:47:08 PM web.1 |  	at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:114)
6:47:08 PM web.1 |  	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:128)
6:47:08 PM web.1 |  	at java.lang.Thread.run(Thread.java:745)
6:47:08 PM web.1 |  Caused by: java.net.ConnectException: Connection refused
6:47:08 PM web.1 |  	at java.net.PlainSocketImpl.socketConnect(Native Method)
6:47:08 PM web.1 |  	at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
6:47:08 PM web.1 |  	at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
6:47:08 PM web.1 |  	at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
6:47:08 PM web.1 |  	at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
6:47:08 PM web.1 |  	at java.net.Socket.connect(Socket.java:589)
6:47:08 PM web.1 |  	at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
6:47:08 PM web.1 |  	at com.mongodb.connection.SocketStream.open(SocketStream.java:58)
6:47:08 PM web.1 |  	... 3 more
6:47:08 PM web.1 |  [main] INFO org.mongodb.driver.cluster - No server chosen by WritableServerSelector from cluster description ClusterDescription{type=UN…
6:47:09 PM web.1 |  [cluster-ClusterId{value='56fda8ece1a1e38897e615c4', description='null'}-ds015869.mlab.com:15869] INFO org.mongodb.driver.connection - …
6:47:09 PM web.1 |  [cluster-ClusterId{value='56fda8ece1a1e38897e615c4', description='null'}-ds015869.mlab.com:15869] INFO org.mongodb.driver.cluster - Mon…
6:47:09 PM web.1 |



 Comments   
Comment by Junwei Zhuge [ 01/Apr/16 ]

Thank you very much. I have fixed this.

It is because a thread is running on port 4567, which is the default port of Jettty.

And I added this `port(Integer.valueOf(System.getenv("PORT")));` to make this project run on Port 5000, which is Heroku's port by default.

I don't know much about this stuff, but it works. BTW, I also changed java-driver 3.2.2 to 2.7.2, it seems that there is something wrong with "DB", I can only use "MongoDatabase" instead of "DB", but using "MongoDatabase" is not a good idea for my project.

Comment by Ross Lawley [ 01/Apr/16 ]

Hi zhugerock@gmail.com,

Just to let you know the JAVA project is specifically for driver based bugs or issues. For questions please use the mailing list or stackoverflow as you will reach and help the broader community.

I'm closing this ticket but if you do post go on to post to the mailing list or stackoverflow please feel free to post a link in this ticket and I'll review there!

Ross

Comment by mahdi mallaki [ 01/Apr/16 ]

Is there a MongoDB running at the time when you see the error message?
Is the MongoDB running accessible from where you are running the Java code? (firewall problems)

I think it is not a java driver bug!
Just to let you know the JAVA project is specifically for driver based bugs or issues. For questions please use the mailing list or stackoverflow as you will reach the broader community.

Generated at Thu Feb 08 08:56:30 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.