Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't access localhost in bazel 0.3.2 #2018

Closed
dfabulich opened this issue Oct 31, 2016 · 8 comments
Closed

Can't access localhost in bazel 0.3.2 #2018

dfabulich opened this issue Oct 31, 2016 · 8 comments
Assignees
Labels
category: sandboxing P2 We'll consider working on this in future. (Assignee optional) type: bug under investigation

Comments

@dfabulich
Copy link
Contributor

dfabulich commented Oct 31, 2016

Consider this repository. https://github.com/dfabulich/bazel-localhost-test

It has a simple WORKSPACE declaring junit and hamcrest_core.

maven_jar(
	name='junit',
	artifact='junit:junit:4.12'
)

maven_jar(
	name='hamcrest_core',
	artifact='org.hamcrest:hamcrest-core:1.3'
)

And the BUILD file has just one test target with the requires-network tag:

java_test(
	name='apptest',
	srcs=glob(['src/test/java/**']),
	test_class='com.redfin.AppTest',
	size="small",
	tags=["requires-network"],
	deps=['@junit//jar', '@hamcrest_core//jar'],
)

The test itself just attempts to print the localhost's hostname.

package com.redfin;

import org.junit.Test;
import java.net.*;
import java.io.*;

public class AppTest {

        @Test
        public void testGo() throws Exception {
                System.out.println(InetAddress.getLocalHost().getHostName());
        }
}

This test passes in bazel 0.3.1 on Ubuntu 16.04.

bazel 0.3.1 version details
Build label: 0.3.1
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Jul 29 09:09:52 2016 (1469783392)
Build timestamp: 1469783392
Build timestamp as int: 1469783392

But on bazel 0.3.2 it fails.

stacktrace
java.net.UnknownHostException: sandbox: sandbox: unknown error
	at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
	at com.redfin.AppTest.testGo(AppTest.java:11)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
	at com.google.testing.junit.runner.junit4.CancellableRequestFactory$CancellableRunner.run(CancellableRequestFactory.java:90)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
	at org.junit.runner.JUnitCore.run(JUnitCore.java:138)
	at com.google.testing.junit.runner.junit4.JUnit4Runner.run(JUnit4Runner.java:112)
	at com.google.testing.junit.runner.BazelTestRunner.runTestsInSuite(BazelTestRunner.java:140)
	at com.google.testing.junit.runner.BazelTestRunner.main(BazelTestRunner.java:79)
Caused by: java.net.UnknownHostException: sandbox: unknown error
	at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
	... 24 more
bazel 0.3.2 version details
Build label: 0.3.2
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Fri Oct 7 17:25:10 2016 (1475861110)
Build timestamp: 1475861110
Build timestamp as int: 1475861110
@dfabulich
Copy link
Contributor Author

This also fails in Bazel 0.4rc3 on Ubuntu 16.04, with the same stacktrace.

Build label: 0.4.0rc3
Build target: bazel-out/local-fastbuild/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Oct 26 13:47:46 2016 (1477489666)
Build timestamp: 1477489666
Build timestamp as int: 1477489666

@dfabulich
Copy link
Contributor Author

dfabulich commented Nov 2, 2016

Is there a workaround possible for this, other than just running the tests outside the sandbox? I thought requires-network should have done the trick, but it didn't.

@laszlocsomor
Copy link
Contributor

Ugh, sorry for the long silence. Redirecting to our sandbox expert @philwo .

@laszlocsomor laszlocsomor added type: bug P2 We'll consider working on this in future. (Assignee optional) labels Nov 3, 2016
@dfabulich
Copy link
Contributor Author

ping?

@dfabulich
Copy link
Contributor Author

@philwo have you had a chance to look at this issue yet? If you (or anybody) can give me a hint where to start, I can try to pull together a pull request.

@philwo
Copy link
Member

philwo commented Dec 6, 2016

@dfabulich So sorry for the delay! I will add your test to the test suite of the sandbox, figure out why it's not working and then fix it. Hope to have something by the end of today.

@philwo
Copy link
Member

philwo commented Dec 6, 2016

The reason for this failure is that SetupUtsNamespace in linux-sandbox-pid1.cc sets the hostname and domainname to "sandbox", which cannot be resolved via /etc/hosts or DNS, which results in the error you're seeing.

I think I'll just set the hostname inside the sandbox to "localhost" and the domainname to an empty value. This should fix the issue (because "localhost" can usually be resolved) and still not leak anything.

Would that work for you? Or would you prefer the hostname to not change at all and the original hostname be visible inside the sandbox?

@dfabulich
Copy link
Contributor Author

I don't have time to test it today, but it "works for me" if the https://github.com/dfabulich/bazel-localhost-test test passes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: sandboxing P2 We'll consider working on this in future. (Assignee optional) type: bug under investigation
Projects
None yet
Development

No branches or pull requests

4 participants