离奇的 Connection reset by peer 和 Broken pipe 的后续的解决方案
AI 摘要
异常仍偶发,遂在 Spring 全局异常处理器中直接过滤并静默忽略含上述字样的 IOException,以暴力方式屏蔽日志噪音。
接上文:https://www.duox.dev/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;
}
}
}这个解决方案很暴力......