public static void checkThreadLeaks() throws IOException { String threadDump = ThreadDumpUtil.takeDumpJSONString(); // Currently we only do sanity check for threads used in the execution engine. // Later we should check if there are leaked storage threads as well. if (threadDump.contains("Operator") || threadDump.contains("SuperActivity") || threadDump.contains("PipelinedPartition")) { System.out.print(threadDump); throw new AssertionError("There are leaked threads in the execution engine."); } }
public static synchronized void halt(int status) { LOGGER.fatal("JVM halting with status {}; thread dump at halt: {}", status, ThreadDumpUtil.takeDumpString()); // try to give time for the log to be emitted... LogManager.shutdown(); Runtime.getRuntime().halt(status); }
public static String takeDumpJSONString() throws IOException { ObjectNode json = takeDumpJSON(); return om.writerWithDefaultPrettyPrinter().writeValueAsString(json); }
public static void checkOpenRunFileLeaks() throws IOException { if (SystemUtils.IS_OS_WINDOWS) { return; } // Only run the check on Linux and MacOS. RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean(); String processName = runtimeMXBean.getName(); String processId = processName.split("@")[0]; // Checks whether there are leaked run files from operators. Process process = Runtime.getRuntime().exec(new String[] { "bash", "-c", "lsof -p " + processId + "|grep waf|wc -l" }); try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) { int runFileCount = Integer.parseInt(reader.readLine().trim()); if (runFileCount != 0) { System.out.print(takeDumpJSONString()); outputLeakedOpenFiles(processId); throw new AssertionError("There are " + runFileCount + " leaked run files."); } } }
@Override public void run() { try { try { LOGGER.info("Shutdown hook called"); } catch (Throwable th) {//NOSONAR } LOGGER.log(Level.INFO, () -> "Thread dump at shutdown: " + ThreadDumpUtil.takeDumpString()); nodeControllerService.stop(); } catch (Throwable th) { // NOSONAR... This is fine since this is shutdown hook LOGGER.log(Level.WARN, "Exception in executing shutdown hook", th); } } }
@Override public void run() { String result; try { result = ThreadDumpUtil.takeDumpJSONString(); } catch (Exception e) { LOGGER.log(Level.WARN, "Exception taking thread dump", e); result = null; } try { ncs.getClusterController(ccId).notifyThreadDump(ncs.getContext().getNodeId(), requestId, result); } catch (Exception e) { LOGGER.log(Level.WARN, "Exception sending thread dump to CC", e); } } }
protected void doStop() throws InterruptedException { // stop recovery if it was ongoing Thread rt = recoveryThread; if (rt != null) { rt.interrupt(); } // stop taking new requests executor.shutdown(); try { // wait 5s before interrupting existing requests executor.awaitTermination(5, TimeUnit.SECONDS); // interrupt executor.shutdownNow(); // wait 30s for interrupted requests to unwind executor.awaitTermination(30, TimeUnit.SECONDS); if (!executor.isTerminated()) { if (LOGGER.isErrorEnabled()) { LOGGER.log(Level.ERROR, "Failed to shutdown http server executor; thread dump: " + ThreadDumpUtil.takeDumpString()); } else { LOGGER.log(Level.ERROR, "Failed to shutdown http server executor"); } } } catch (Exception e) { LOGGER.log(Level.ERROR, "Error while shutting down http server executor", e); } channel.close(); channel.closeFuture().sync(); }
callback.setValue(ThreadDumpUtil.takeDumpJSONString()); } catch (Exception e) { LOGGER.log(Level.WARN, "Exception taking CC thread dump", e);