Skip to content

Commit

Permalink
Add shutdown hook for WebSphere and checkError() to detect disconnect…
Browse files Browse the repository at this point in the history
…ed client (issue Netflix#346)

WebSphere won't shutdown a servlet until after a 60 second timeout if
there is an  instance of the servlet executing a request.  Add a
shutdown method to enable a hook to notify Hystrix to shutdown.  You
must invoke this method at app server shutdown, perhaps from another
servlet's destroy() method.

Also added explicit checkError() in poller loop to check for
disconnected client.
  • Loading branch information
jboyd01 committed Jan 20, 2015
1 parent 8a39e8c commit 223b1ea
Showing 1 changed file with 20 additions and 1 deletion.
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

0 comments on commit 223b1ea

Please sign in to comment.