From 757202b63e98ca0e9b60ca811f48054b0b4cefc7 Mon Sep 17 00:00:00 2001 From: Mark Payne Date: Wed, 25 Nov 2015 16:21:58 -0500 Subject: [PATCH] NIFI-1059: If we get an IOException when telling NiFi to shutdown, just kill NiFi immediately, instead of giving up Signed-off-by: joewitt --- .../java/org/apache/nifi/bootstrap/RunNiFi.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java index c8d1f4de0c..a3d3de7dc3 100644 --- a/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java +++ b/nifi-bootstrap/src/main/java/org/apache/nifi/bootstrap/RunNiFi.java @@ -627,13 +627,14 @@ public class RunNiFi { final Properties nifiProps = loadProperties(logger); final String secretKey = nifiProps.getProperty("secret.key"); + final String pid = nifiProps.getProperty("pid"); try (final Socket socket = new Socket()) { logger.debug("Connecting to NiFi instance"); - socket.setSoTimeout(60000); + socket.setSoTimeout(10000); socket.connect(new InetSocketAddress("localhost", port)); logger.debug("Established connection to NiFi instance."); - socket.setSoTimeout(60000); + socket.setSoTimeout(10000); logger.debug("Sending SHUTDOWN Command to port {}", port); final OutputStream out = socket.getOutputStream(); @@ -654,7 +655,6 @@ public class RunNiFi { if (SHUTDOWN_CMD.equals(response)) { logger.info("Apache NiFi has accepted the Shutdown Command and is shutting down now"); - final String pid = nifiProps.getProperty("pid"); if (pid != null) { final Properties bootstrapProperties = new Properties(); try (final FileInputStream fis = new FileInputStream(bootstrapConfigFile)) { @@ -703,7 +703,13 @@ public class RunNiFi { logger.error("When sending SHUTDOWN command to NiFi, got unexpected response {}", response); } } catch (final IOException ioe) { - logger.error("Failed to send shutdown command to port {} due to {}", new Object[]{port, ioe.toString(), ioe}); + if (pid == null) { + logger.error("Failed to send shutdown command to port {} due to {}. No PID found for the NiFi process, so unable to kill process; " + + "the process should be killed manually.", new Object[] {port, ioe.toString(), ioe}); + } else { + logger.error("Failed to send shutdown command to port {} due to {}. Will kill the NiFi Process with PID {}.", new Object[] {port, ioe.toString(), ioe, pid}); + killProcessTree(pid, logger); + } } finally { if (lockFile.exists() && !lockFile.delete()) { logger.error("Failed to delete lock file {}; this file should be cleaned up manually", lockFile);