Skip to content

Commit bf6922a

Browse files
committed
Cleaner implementation of server detecting client disconnection in sampling stream
1 parent 11ca011 commit bf6922a

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

hystrix-contrib/hystrix-metrics-event-stream/src/main/java/com/netflix/hystrix/contrib/sample/stream/HystrixSampleSseServlet.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,12 @@ public void onError(Throwable e) {
146146
@Override
147147
public void onNext(String sampleDataAsString) {
148148
if (sampleDataAsString != null) {
149-
try {
150-
writer.print("data: " + sampleDataAsString + "\n\n");
151-
// explicitly check for client disconnect - PrintWriter does not throw exceptions
152-
if (writer.checkError()) {
153-
throw new IOException("io error");
154-
}
155-
writer.flush();
156-
} catch (IOException ioe) {
149+
writer.print("data: " + sampleDataAsString + "\n\n");
150+
// explicitly check for client disconnect - PrintWriter does not throw exceptions
151+
if (writer.checkError()) {
157152
moreDataWillBeSent.set(false);
158153
}
154+
writer.flush();
159155
}
160156
}
161157
});
@@ -167,17 +163,16 @@ public void onNext(String sampleDataAsString) {
167163
writer.print("ping: \n\n");
168164
// explicitly check for client disconnect - PrintWriter does not throw exceptions
169165
if (writer.checkError()) {
170-
throw new IOException("io error");
166+
moreDataWillBeSent.set(false);
171167
}
172168
writer.flush();
173169
} catch (InterruptedException e) {
174170
moreDataWillBeSent.set(false);
175-
} catch (IOException ioe) {
176-
moreDataWillBeSent.set(false);
177171
}
178172
}
179173
}
180174
} finally {
175+
System.out.println("Exiting the server thread, current count = " + getNumberCurrentConnections());
181176
decrementCurrentConcurrentConnections();
182177
if (sampleSubscription != null && !sampleSubscription.isUnsubscribed()) {
183178
sampleSubscription.unsubscribe();

0 commit comments

Comments
 (0)