离奇的 Connection reset by peer 和 Broken pipe 的后续的解决方案
接上文:https://www.duozai.cn/post/49.html
时隔好几个月,原本以为项目出现的 java.io.IOException: Connection reset by peer 的问题已经彻底解决,然而当我看错误日志的时候,居然还会偶尔出现,见鬼了......
补充解决方案:自定义异常处理类,直接忽略 Broken pipe 和 Connection reset by pee。
@ControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public ModelAndView handleGlobalException(Exception ex) {
if (StringUtils.containsIgnoreCase(e.toString(), "Broken pipe") || StringUtils.containsIgnoreCase(e.toString(), "Connection reset by peer")) {
// socket closed
return null;
}
}
}这个解决方案很暴力......