joelittlejohn / embedmongo-maven-plugin

Maven plugin wrapper for the flapdoodle.de embedded MongoDB API
Apache License 2.0
88 stars 51 forks source link

Exception on Network.localhostIsIPv6() should be handled gracefully #13

Closed whaley closed 11 years ago

whaley commented 11 years ago

When working at local coffee shop I get the following on running the start goal.

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.770s
[INFO] Finished at: Thu Mar 07 07:09:10 EST 2013
[INFO] Final Memory: 27M/354M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.github.joelittlejohn.embedmongo:embedmongo-maven-plugin:0.1.5:start (start) on project pem-system-tests-public-api-usage: Unable to determine if localhost is ipv6: capitalg: capitalg: nodename nor servname provided, or not known -> [Help 1]
[ERROR]

This also seems to happen if I disconnect myself and go offline.

In another maven module where I'm using de.flapdoodle.embed.mongo.MongodStarter in code as opposed to using your plugin as part of pre-integration-test and post-integration-test, I am wrapping MongodStarter jin this way to prevent that from happening.

public void startEmbeddedMongo() throws Exception {
    MongodConfig config = new MongodConfig(Version.V2_2_1, mongoPort, isLocalhostIPV6());
    MongodStarter runtime = MongodStarter.getDefaultInstance();
    mongod = runtime.prepare(config);
    mongod.start();
}

private boolean isLocalhostIPV6() {
    boolean isIp6;
    try {
        isIp6 = Network.localhostIsIPv6();
    } catch (Exception e) {
        isIp6 = false;
    }
    return isIp6;
}

If Network.localhostIsIPV6() fails for whatever reason, I'm just blithely setting MongodConfig's ipv6 property to false.

joelittlejohn commented 11 years ago

Just waiting on a release of the upstream flapdoodle API to fix this.

michaelmosmann commented 11 years ago

Hmm.. i had similar issues working on my laptop without any network, but the current code did handle this well. So there must be some other cause for this.

Can you answer me the following questions?

whaley commented 11 years ago

On which platform did you get this error?

OSX (10.8)

Does "ping localhost" works?

Turns out that this not working is because my hostname is set to something else, but I didn't have an entry in /etc/hosts for that particular hostname for 127.0.0.1. That actually makes the problem go away too.

joelittlejohn commented 11 years ago

@michaelmosmann I guess we could close flapdoodle-oss/de.flapdoodle.embed.process#3 and not merge the change, but I think this is a common configuration problem and probably worth coding around if we can.

michaelmosmann commented 11 years ago

I think i will make some more checks an printout a warning message for helping to solve this problem...

joelittlejohn commented 11 years ago

Fixed (a warning is displayed) by upgrading to embedmongo 1.31.

joelittlejohn commented 9 years ago

Note: there seems to be a problem calling functions like Network.localhostIsIPv6() on OSX in Java 7. The result is an UnknownHostException with a message like:

jlittlej: jlittlej: nodename nor servname provided, or not known.

If you experience this, the suggested workaround seems to be to add your hostname to /etc/hosts.

In my case this meant adding:

127.0.0.1    jlittlej

to /etc/hosts.