Skip to content


fix: align ip version preference for the wrapped emulator (#1052)
Browse files Browse the repository at this point in the history
* fix: align ip version preference for the wrapped  emulator

When the  emulator wrapper is started with on a machine that defaults to ipv4,
the golang emulator and the java client will pick different ip stacks and not be able to connect. This change will
use java to resolve the localhost's ip address and push it down to the golang emulator

* remove debug

* whitespace
  • Loading branch information
igorbernstein2 committed Jan 5, 2022
1 parent 1ee5773 commit 9dc93c5
Showing 1 changed file with 18 additions and 1 deletion.
Expand Up @@ -25,10 +25,13 @@
import java.nio.file.Path;
import java.util.Locale;
import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
Expand Down Expand Up @@ -98,10 +101,24 @@ public synchronized void start() throws IOException, TimeoutException, Interrupt
this.port = getAvailablePort();

// Try to align the localhost address across java & golang emulator
// This should fix issues on systems that default to ipv4 but the jvm is started with
Optional<String> localhostAddress = Optional.empty();
try {
localhostAddress = Optional.of(InetAddress.getByName(null).getHostAddress());
} catch (UnknownHostException e) {

// Workaround
for (int attemptsLeft = 3; process == null; attemptsLeft--) {
try {
process = Runtime.getRuntime().exec(String.format("%s -port %d", executable, port));
String cmd = executable.toString();
if (localhostAddress.isPresent()) {
cmd += String.format(" -host [%s]", localhostAddress.get());
cmd += String.format(" -port %d", port);
process = Runtime.getRuntime().exec(cmd);
} catch (IOException e) {
if (attemptsLeft > 0) {
Expand Down

0 comments on commit 9dc93c5

Please sign in to comment.