[JAVA-714] Connection refused by Java driver but allowed by shell Created: 13/Dec/12  Updated: 15/Dec/12  Resolved: 15/Dec/12

Status: Closed
Project: Java Driver
Component/s: Connection Management
Affects Version/s: 2.9.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Prasan Kaikini Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Mac 10.7.5



 Description   

I had been able to connect and work with the database, but all of a sudden I started getting "Connection refused" errors. I can still connect to mongod from the command line. I checked the bug reports and changed host from "localhost" to 127.0.0.1. But that hasn't helped. Here's the stack-trace:
Caused by: com.mongodb.MongoException$Network: can't call something : local/192.168.1.44:27017/test
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:227)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:305)
at com.mongodb.DB.command(DB.java:160)
at com.mongodb.DB.command(DB.java:183)
at com.mongodb.DB.command(DB.java:144)
at com.mongodb.DBCollection.drop(DBCollection.java:765)
at com.mongodb.DBApiLayer$MyCollection.drop(DBApiLayer.java:206)
at org.springframework.data.mongodb.core.MongoTemplate$7.doInCollection(MongoTemplate.java:430)
at org.springframework.data.mongodb.core.MongoTemplate$7.doInCollection(MongoTemplate.java:428)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:368)
... 31 more
Caused by: java.io.IOException: couldn't connect to [local/192.168.1.44:27017] bc:java.net.ConnectException: Connection refused
at com.mongodb.DBPort._open(DBPort.java:228)
at com.mongodb.DBPort.go(DBPort.java:112)
at com.mongodb.DBPort.call(DBPort.java:79)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:218)

Here's my Spring configuration for Mongo:
<bean id="mongoTemplate" class="org.springframework.data.mongodb.core.MongoTemplate">
<constructor-arg name="mongoDbFactory" ref="mongoDbFactory" />
</bean>

<mongo:db-factory id="mongoDbFactory" dbname="hledb" host="127.0.0.1" port="27017"/>



 Comments   
Comment by Jeffrey Yemin [ 15/Dec/12 ]

OK, thanks for the update. Let me know if you figure out what Tomcat is doing to cause this problem, as perhaps others are encountering it as well.

Comment by Prasan Kaikini [ 15/Dec/12 ]

Here's my /etc/hosts:
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

Thanks for letting me not to use 2.9.1.

Also, I think it had something to do with my Tomcat. I wrote a small Java test program to try to access mongo without Tomcat, and it worked. I restarted Tomcat, but that didn't help. I restarted my laptop, but that didn't help either. So I reinstalled Tomcat and that fixed it.

Comment by Jeffrey Yemin [ 15/Dec/12 ]

Anything interesting in /etc/hosts? Can you post it?

Comment by Jeffrey Yemin [ 15/Dec/12 ]

Not sure what's happening here, but wanted to let you know ASAP not to use 2.9.1 as it contains a serious bug. Please upgrade to 2.9.3 or 2.10.1.

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