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

Add shutdown hook for WebSphere and checkError() to detect disconnected client #530

Merged
merged 1 commit into from
Jan 20, 2015
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 @@ -63,7 +63,21 @@ public class HystrixMetricsStreamServlet extends HttpServlet {
private static AtomicInteger concurrentConnections = new AtomicInteger(0);
private static DynamicIntProperty maxConcurrentConnections = DynamicPropertyFactory.getInstance().getIntProperty("hystrix.stream.maxConcurrentConnections", 5);

private volatile boolean isDestroyed = false;
private static volatile boolean isDestroyed = false;

/**
* WebSphere won't shutdown a servlet until after a 60 second timeout if there is an instance of the servlet executing
* a request. Add this method to enable a hook to notify Hystrix to shutdown. You must invoke this method at
* shutdown, perhaps from some other serverlet's destroy() method.
*/
public static void shutdown() {
isDestroyed = true;
}

@Override
public void init() throws ServletException {
isDestroyed = false;
}

/**
* Handle incoming GETs
Expand Down Expand Up @@ -146,6 +160,11 @@ private void handleRequest(HttpServletRequest request, HttpServletResponse respo
// after outputting all the messages we will flush the stream
response.flushBuffer();

// explicitly check for client disconnect - PrintWriter does not throw exceptions
if (response.getWriter().checkError()) {
throw new IOException("io error");
}

// now wait the 'delay' time
Thread.sleep(delay);
}
Expand Down