From bf6922a32b4980fda0ede4538ec2e3523551083b Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Wed, 14 Dec 2016 15:07:16 -0800 Subject: [PATCH 1/2] Cleaner implementation of server detecting client disconnection in sampling stream --- .../sample/stream/HystrixSampleSseServlet.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) 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 b366af1e0..530fd1ee5 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 @@ -146,16 +146,12 @@ public void onError(Throwable e) { @Override public void onNext(String sampleDataAsString) { if (sampleDataAsString != null) { - try { - writer.print("data: " + sampleDataAsString + "\n\n"); - // explicitly check for client disconnect - PrintWriter does not throw exceptions - if (writer.checkError()) { - throw new IOException("io error"); - } - writer.flush(); - } catch (IOException ioe) { + writer.print("data: " + sampleDataAsString + "\n\n"); + // explicitly check for client disconnect - PrintWriter does not throw exceptions + if (writer.checkError()) { moreDataWillBeSent.set(false); } + writer.flush(); } } }); @@ -167,17 +163,16 @@ public void onNext(String sampleDataAsString) { writer.print("ping: \n\n"); // explicitly check for client disconnect - PrintWriter does not throw exceptions if (writer.checkError()) { - throw new IOException("io error"); + moreDataWillBeSent.set(false); } writer.flush(); } catch (InterruptedException e) { moreDataWillBeSent.set(false); - } catch (IOException ioe) { - moreDataWillBeSent.set(false); } } } } finally { + System.out.println("Exiting the server thread, current count = " + getNumberCurrentConnections()); decrementCurrentConcurrentConnections(); if (sampleSubscription != null && !sampleSubscription.isUnsubscribed()) { sampleSubscription.unsubscribe(); From 58962fecb96930cc880e6d35ad4bb127b2577e02 Mon Sep 17 00:00:00 2001 From: Matt Jacobs Date: Wed, 14 Dec 2016 15:10:17 -0800 Subject: [PATCH 2/2] Removing accidental println --- .../hystrix/contrib/sample/stream/HystrixSampleSseServlet.java | 1 - 1 file changed, 1 deletion(-) 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 530fd1ee5..75df0c380 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 @@ -172,7 +172,6 @@ public void onNext(String sampleDataAsString) { } } } finally { - System.out.println("Exiting the server thread, current count = " + getNumberCurrentConnections()); decrementCurrentConcurrentConnections(); if (sampleSubscription != null && !sampleSubscription.isUnsubscribed()) { sampleSubscription.unsubscribe();