Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1430 by detecting case when client connect/disconnects before me… #1442

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid the cost of creating and throwing the exception, can you call moreDataWillBeSent.set(false); instead?

}
writer.flush();
} catch (InterruptedException e) {
moreDataWillBeSent.set(false);
} catch (IOException ioe) {
moreDataWillBeSent.set(false);
}
}
}
Expand Down