Skip to content
Permalink
Browse files

[FIXED JENKINS-10421] Use Proc.joinWithTimeout to prevent adb hangs.

  • Loading branch information
jorgenpt authored and orrc committed Sep 8, 2011
1 parent 0515f6c commit 4cd68f5bbd13ab6800c050d4caa483e53723488e
Showing with 15 additions and 9 deletions.
  1. +15 −9 src/main/java/hudson/plugins/android_emulator/AndroidEmulator.java
@@ -28,6 +28,7 @@
import hudson.util.ForkOutputStream;
import hudson.util.FormValidation;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
@@ -42,6 +43,7 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@@ -646,17 +648,21 @@ private boolean waitForBootCompletion(final PrintStream logger, final Launcher l
ByteArrayOutputStream stream = new ByteArrayOutputStream(4);

// Run "getprop"
launcher.launch().cmds(bootCheckCmd).stdout(stream).start().join();

// Check output
String result = stream.toString().trim();
if (result.equals("1")) {
return true;
Proc proc = launcher.launch().cmds(bootCheckCmd).stdout(stream).start();
long waitTimeout = timeout / 8;
int retVal = proc.joinWithTimeout(waitTimeout, TimeUnit.MILLISECONDS, StreamTaskListener.fromStderr());

if (retVal == 0) {
// Check output
String result = stream.toString().trim();
if (result.equals("1")) {
return true;
}

// Otherwise continue...
Thread.sleep(sleep);
}

// Otherwise continue...
Thread.sleep(sleep);

// Ensure the emulator is connected to adb, in case it had crashed
launcher.launch().cmds(connectCmd).start().join();
}

0 comments on commit 4cd68f5

Please sign in to comment.
You can’t perform that action at this time.