Skip to content
Permalink
Browse files

[JENKINS-21695] - The CompressionFilter.uncaughtExceptionHandler must…

… not attempt to write to a committed response. (#2834)

(cherry picked from commit 0c7e7bb)
  • Loading branch information...
jglick authored and olivergondza committed Apr 21, 2017
1 parent 1c56f01 commit 161095e01b649e5453e65d5277f3bbcbefa480f4
Showing with 12 additions and 4 deletions.
  1. +12 −4 core/src/main/java/hudson/init/impl/InstallUncaughtExceptionHandler.java
@@ -20,11 +20,18 @@
* @author Kohsuke Kawaguchi
*/
public class InstallUncaughtExceptionHandler {

private static final Logger LOGGER = Logger.getLogger(InstallUncaughtExceptionHandler.class.getName());

@Initializer
public static void init(final Jenkins j) throws IOException {
CompressionFilter.setUncaughtExceptionHandler(j.servletContext, new UncaughtExceptionHandler() {
@Override
public void reportException(Throwable e, ServletContext context, HttpServletRequest req, HttpServletResponse rsp) throws ServletException, IOException {
if (rsp.isCommitted()) {
LOGGER.log(Level.WARNING, null, e);
return;
}
req.setAttribute("javax.servlet.error.exception",e);
try {
WebApp.get(j.servletContext).getSomeStapler()
@@ -38,10 +45,10 @@ public void reportException(Throwable e, ServletContext context, HttpServletRequ
});
try {
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
DefaultUncaughtExceptionHandler.LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler.");
LOGGER.log(Level.FINE, "Successfully installed a global UncaughtExceptionHandler.");
}
catch (SecurityException ex) {
DefaultUncaughtExceptionHandler.LOGGER.log(Level.SEVERE,
LOGGER.log(Level.SEVERE,
"Failed to set the default UncaughtExceptionHandler. " +
"If any threads die due to unhandled coding errors then there will be no logging of this information. " +
"The lack of this diagnostic information will make it harder to track down issues which will reduce the supportability of Jenkins. " +
@@ -53,8 +60,6 @@ public void reportException(Throwable e, ServletContext context, HttpServletRequ
/** An UncaughtExceptionHandler that just logs the exception */
private static class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {

private static final Logger LOGGER = Logger.getLogger(InstallUncaughtExceptionHandler.class.getName());

@Override
public void uncaughtException(Thread t, Throwable ex) {
// if this was an OutOfMemoryError then all bets about logging are off - but in the absence of anything else...
@@ -65,4 +70,7 @@ public void uncaughtException(Thread t, Throwable ex) {
}

}

private InstallUncaughtExceptionHandler() {}

}

0 comments on commit 161095e

Please sign in to comment.
You can’t perform that action at this time.