jirutka / embedmongo-spring

Spring Factory Bean for “Embedded” MongoDB
44 stars 15 forks source link

EmbeddedMongoBuilder#bindToLoopbackAddress() #5

Closed sdavids closed 10 years ago

sdavids commented 10 years ago
@Before
public void setUp() throws IOException {
    mongo = new EmbeddedMongoBuilder().build();
}

@@

org.springframework.dao.DataAccessResourceFailureException: Timed out while waiting to connect after 10000 ms; nested exception is com.mongodb.MongoTimeoutException: Timed out while waiting to connect after 10000 ms at com.mongodb.BaseCluster.getDescription(BaseCluster.java:131) at com.mongodb.DBTCPConnector.getClusterDescription(DBTCPConnector.java:396) at com.mongodb.DBTCPConnector.getType(DBTCPConnector.java:569) at com.mongodb.DBTCPConnector.getReplicaSetStatus(DBTCPConnector.java:364) at com.mongodb.Mongo.getReplicaSetStatus(Mongo.java:465) at com.mongodb.DB.getCommandReadPreference(DB.java:86) at com.mongodb.DB.command(DB.java:314) at com.mongodb.DB.command(DB.java:296) at com.mongodb.DB.command(DB.java:371) at com.mongodb.DB.command(DB.java:243) at com.mongodb.DBCollection.drop(DBCollection.java:1014) at com.mongodb.DBCollectionImpl.drop(DBCollectionImpl.java:285) at org.springframework.data.mongodb.core.MongoTemplate$6.doInCollection(MongoTemplate.java:472) at org.springframework.data.mongodb.core.MongoTemplate$6.doInCollection(MongoTemplate.java:470) at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:410) at org.springframework.data.mongodb.core.MongoTemplate.dropCollection(MongoTemplate.java:470) at org.springframework.data.mongodb.core.MongoTemplate.dropCollection(MongoTemplate.java:466) at test,Test.setUp(Test.java:37)

Sep 29, 2014 3:11:16 PM de.flapdoodle.embed.mongo.runtime.Mongod sendShutdown WARNING: --------------------------------------- Your localhost (192.168.2.103) is not a loopback adress

@@

Please add

public EmbeddedMongoBuilder bindToLoopbackAddress() {
    try {
        this.bindIp = ((InetAddress) InetAddress.class.getMethod("getLoopbackAddress")
            .invoke(null)).getHostAddress();
    } catch (NoSuchMethodException e) {
        this.bindIp = "127.0.0.1";
    } catch (InvocationTargetException e) {
        this.bindIp = "127.0.0.1";
    } catch (IllegalAccessException e) {
        this.bindIp = "127.0.0.1";
    } catch (ClassCastException e) {
        this.bindIp = "127.0.0.1";
    }
    return this;
}

or if you want to upgrade to Java 7

public EmbeddedMongoBuilder bindToLoopbackAddress() {
    this.bindIp = InetAddress.getLoopbackAddress().getHostAddress();
    return this;
}

@@@@

Thanks.

You might even consider using the loopback address the default -- instead of localhost.

jirutka commented 10 years ago

Localhost should be always a loopback interface. Why do you have a non-loopback interface on localhost?

sdavids commented 10 years ago

Well, I don't know actually :D

localhost:tmp user$ cat /etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost 
fe80::1%lo0 localhost
localhost:tmp user$ ifconfig | grep 192 -B 3
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether b8:f6:b1:18:01:a1 
    inet6 fe80::baf6:b1ff:fe18:1a1%en0 prefixlen 64 scopeid 0x4 
    inet 192.168.2.103 netmask 0xffffff00 broadcast 192.168.2.255
localhost:tmp user$ jjs
jjs> java.net.InetAddress.getLoopbackAddress()
localhost/127.0.0.1
jjs> java.net.InetAddress.getByName("localhost")
localhost/192.168.2.103
jirutka commented 10 years ago

Okay, I’ve changed the default bindIp to InetAddress.getLoopbackAddress().getHostAddress() and released a new version (it’ll be in Maven Central in few hours).

However, you should really fix your network settings, localhost should be a loopback interface, many software relies on it. Your /etc/hosts looks fine, so it must be messed somewhere else. What system is that – OS X or *BSD?

sdavids commented 10 years ago

However, you should really fix your network settings, localhost should be a loopback interface, many software relies on it. Your /etc/hosts looks fine, so it must be messed somewhere else. What system is that – OS X or *BSD? OS X

Thanks,

Sebastian