Skip to content

Commit

Permalink
Catch SocketException instead of BindException to handle disabled IPv6
Browse files Browse the repository at this point in the history
**Problem:**
`StarlarkDebugServerTest` and `DebugServerTransportTest` fails with error `java.net.SocketException: Protocol family unavailable` in some enviroments.

**Explanation:**
If IPv6 is disabled in docker container ServerSocket fails to bind to ::1 with `java.net.SocketException`.
But bazel tests falls back to IPv4 only if `java.net.BindException` (subclass of `java.net.SocketException`) occurs.
Let's catch more generic `java.net.SocketException`

Closes #11400.

PiperOrigin-RevId: 311721734
  • Loading branch information
nikola-sh authored and Copybara-Service committed May 15, 2020
1 parent 3a634fa commit 2ed2479
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
Expand Up @@ -23,11 +23,11 @@
import com.google.devtools.build.lib.starlarkdebugging.StarlarkDebuggingProtos.DebugRequest;
import com.google.devtools.build.lib.starlarkdebugging.StarlarkDebuggingProtos.StartDebuggingRequest;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -90,7 +90,7 @@ private static ServerSocket getServerSocket() throws IOException {
// and if that fails, try again with IPv4.
try {
return new ServerSocket(0, 1, InetAddress.getByName("[::1]"));
} catch (BindException e) {
} catch (SocketException e) {
return new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
}
}
Expand Down
Expand Up @@ -49,9 +49,9 @@
import com.google.devtools.build.lib.syntax.StarlarkThread;
import com.google.devtools.build.lib.syntax.SyntaxError;
import java.io.IOException;
import java.net.BindException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.SocketException;
import java.time.Duration;
import java.util.Collection;
import java.util.List;
Expand Down Expand Up @@ -100,7 +100,7 @@ private static ServerSocket getServerSocket() throws IOException {
// and if that fails, try again with IPv4.
try {
return new ServerSocket(0, 1, InetAddress.getByName("[::1]"));
} catch (BindException e) {
} catch (SocketException e) {
return new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
}
}
Expand Down

0 comments on commit 2ed2479

Please sign in to comment.