未验证 提交 96c38bec 编写于 作者: O Oleg Nenashev 提交者: GitHub

Merge pull request #3214 from jglick/UncaughtExceptionHandler-EOFException

UncaughtExceptionHandler should avoid reporting EOFException
package hudson.init.impl;
import hudson.init.Initializer;
import java.io.EOFException;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.WebApp;
import org.kohsuke.stapler.compression.CompressionFilter;
......@@ -17,7 +18,7 @@ import java.util.logging.Logger;
import org.kohsuke.stapler.Stapler;
/**
* @author Kohsuke Kawaguchi
* Deals with exceptions that get thrown all the way up to the Stapler rendering layer.
*/
public class InstallUncaughtExceptionHandler {
......@@ -25,23 +26,19 @@ public class InstallUncaughtExceptionHandler {
@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 {
CompressionFilter.setUncaughtExceptionHandler(j.servletContext, (e, context, req, rsp) -> {
if (rsp.isCommitted()) {
LOGGER.log(Level.WARNING, null, e);
LOGGER.log(isEOFException(e) ? Level.FINE : Level.WARNING, null, e);
return;
}
req.setAttribute("javax.servlet.error.exception",e);
try {
WebApp.get(j.servletContext).getSomeStapler()
.invoke(req,rsp, Jenkins.getInstance(), "/oops");
WebApp.get(j.servletContext).getSomeStapler().invoke(req, rsp, Jenkins.get(), "/oops");
} catch (ServletException | IOException x) {
if (!Stapler.isSocketException(x)) {
throw x;
}
}
}
});
try {
Thread.setDefaultUncaughtExceptionHandler(new DefaultUncaughtExceptionHandler());
......@@ -57,6 +54,16 @@ public class InstallUncaughtExceptionHandler {
}
}
private static boolean isEOFException(Throwable e) {
if (e == null) {
return false;
} else if (e instanceof EOFException) {
return true;
} else {
return isEOFException(e.getCause());
}
}
/** An UncaughtExceptionHandler that just logs the exception */
private static class DefaultUncaughtExceptionHandler implements Thread.UncaughtExceptionHandler {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册