Skip to content

Commit 1722d69

Browse files
authored
Merge pull request Netflix#1561 from mattrjacobs/add-error-handling-sample-sse-servlet
Add exception-handling to interactions with servlet writers
2 parents d3e0991 + b46a563 commit 1722d69

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -146,12 +146,16 @@ public void onError(Throwable e) {
146146
@Override
147147
public void onNext(String sampleDataAsString) {
148148
if (sampleDataAsString != null) {
149-
writer.print("data: " + sampleDataAsString + "\n\n");
150-
// explicitly check for client disconnect - PrintWriter does not throw exceptions
151-
if (writer.checkError()) {
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+
moreDataWillBeSent.set(false);
154+
}
155+
writer.flush();
156+
} catch (Exception ex) {
152157
moreDataWillBeSent.set(false);
153158
}
154-
writer.flush();
155159
}
156160
}
157161
});
@@ -166,7 +170,7 @@ public void onNext(String sampleDataAsString) {
166170
moreDataWillBeSent.set(false);
167171
}
168172
writer.flush();
169-
} catch (InterruptedException e) {
173+
} catch (Exception ex) {
170174
moreDataWillBeSent.set(false);
171175
}
172176
}

0 commit comments

Comments
 (0)