From 62d9c30e61576a9e1b164ebcb5b340454ccd56be Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Wed, 14 Dec 2016 14:39:09 -0800 Subject: [PATCH] Fix #1430 by detecting case when client connect/disconnects before metrics start getting emitted --- .../contrib/sample/stream/HystrixSampleSseServlet.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java index ca0839de9..b366af1e0 100644 --- a/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java +++ b/hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java @@ -163,8 +163,17 @@ public void onNext(String sampleDataAsString) { while (moreDataWillBeSent.get() && !isDestroyed) { try { Thread.sleep(pausePollerThreadDelayInMs); + //in case stream has not started emitting yet, catch any clients which connect/disconnect before emits start + writer.print("ping: \n\n"); + // explicitly check for client disconnect - PrintWriter does not throw exceptions + if (writer.checkError()) { + throw new IOException("io error"); + } + writer.flush(); } catch (InterruptedException e) { moreDataWillBeSent.set(false); + } catch (IOException ioe) { + moreDataWillBeSent.set(false); } } }