Skip to content

Commit

Permalink
Merge pull request #2124 from warunalakshitha/fix_hang
Browse files Browse the repository at this point in the history
Add dump thread logic temporary
  • Loading branch information
warunalakshitha authored Dec 11, 2024
2 parents 8d6c5ca + 991b29f commit f9dba76
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.runtime.api.values.BString;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;

import static io.ballerina.stdlib.graphql.runtime.utils.ModuleUtils.getModule;

/**
Expand All @@ -36,6 +41,19 @@ public class Utils {
private Utils() {
}

static {
Thread.startVirtualThread(() -> {
try {
Thread.sleep(5 * 60 * 1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
}

public static final PrintStream OUT = System.out;
public static final PrintStream ERROR = System.err;

// Inter-op function names
private static final String EXECUTE_RESOURCE_FUNCTION = "executeQueryResource";
private static final String EXECUTE_INTERCEPTOR_FUNCTION = "executeInterceptor";
Expand Down Expand Up @@ -105,4 +123,33 @@ public static void handleBErrorAndExit(BError bError) {
// Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714
System.exit(1);
}

public static void dumpThreads() {
try {
// Get the current process ID (PID)
String pid = ManagementFactory.getRuntimeMXBean().getName().split("@")[0];

// Build the jcmd command
String command = "jcmd " + pid;

// Execute the jcmd command
Process process = Runtime.getRuntime().exec(command);

// Read the output of the command
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
OUT.println(line);
}
}

// Wait for the process to complete
int exitCode = process.waitFor();
if (exitCode != 0) {
ERROR.println("jcmd command failed with exit code: " + exitCode);
}
} catch (Exception error) {
error.printStackTrace();
}
}
}
1 change: 1 addition & 0 deletions native/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
requires io.ballerina.stdlib.graphql.commons;
requires io.ballerina.lang;
requires jdk.jshell;
requires java.management;
}
5 changes: 5 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
<Bug pattern="DM_EXIT" />
</And>
</Match>
<Match>
<And>
<Class name="io.ballerina.stdlib.graphql.runtime.utils.Utils" />
</And>
</Match>
</FindBugsFilter>

0 comments on commit f9dba76

Please sign in to comment.