Skip to content

Commit

Permalink
Don't wait forever when dumping open file handles
Browse files Browse the repository at this point in the history
  • Loading branch information
blindpirate committed Feb 18, 2020
1 parent b1ba9e7 commit f4e1d67
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions gradle/DumpOpenFilesOnFailure.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,40 @@
import java.net.*;
import java.util.*;
import java.util.stream.*;
import java.util.concurrent.*;

public class DumpOpenFiles {
private static ExecutorService threadPool = Executors.newCachedThreadPool();

public static void main(String[] args) throws Exception {
if ("SUCCESS".equals(System.getenv("PREV_BUILD_STATUS"))) {
System.out.println("All previous build steps succeeds, skip.");
System.exit(0);
}

for (String port : parsePorts()) {
String url = "http://localhost:" + port + "/dump";
System.out.println("Sending request to " + url);
try (BufferedReader response = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
String line = null;
while ((line = response.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();

try {
for (String port : parsePorts()) {
Future<Void> future = (Future<Void>) threadPool.submit(() -> dumpOpenFilesFor(port));
future.get(60, TimeUnit.SECONDS);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
System.exit(0);
}
}

private static void dumpOpenFilesFor(String port) {
String url = "http://localhost:" + port + "/dump";
System.out.println("Sending request to " + url);
try (BufferedReader response = new BufferedReader(new InputStreamReader(new URL(url).openStream()))) {
String line = null;
while ((line = response.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
e.printStackTrace();
}
}

Expand Down

0 comments on commit f4e1d67

Please sign in to comment.