From e6d8cd6dfc864b37da9c177c6e9da8c9ce529fd1 Mon Sep 17 00:00:00 2001 From: BGehrels Date: Tue, 29 Apr 2014 17:50:25 +0200 Subject: [PATCH] Handling InterruptedExceptions in the HystrixMetricsStreamServlet Some environments like spring boots embedded Tomcat interrupt the worker threads on shutdown. Interupting a thread is the Java way to politely ask it to gracefully stop doing long running things. Since serving an event stream is a long running thing, we should stop sending the stream and stop polling, whenever an InterruptedException occures. --- .../metrics/eventstream/HystrixMetricsStreamServlet.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java index e26624845..1b3616692 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/metrics/eventstream/HystrixMetricsStreamServlet.java @@ -150,6 +150,10 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo // now wait the 'delay' time Thread.sleep(delay); } + } catch (InterruptedException e) { + poller.shutdown(); + logger.debug("InterruptedException. Will stop polling."); + Thread.currentThread().interrupt(); } catch (IOException e) { poller.shutdown(); // debug instead of error as we expect to get these whenever a client disconnects or network issue occurs