Tomcat Acces中的HTTP Statuscode 500登录ClientAbortException / BrokenPipe [英] HTTP Statuscode 500 in Tomcat AccesLog on ClientAbortException / BrokenPipe

查看:178
本文介绍了Tomcat Acces中的HTTP Statuscode 500登录ClientAbortException / BrokenPipe的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们与Kibana一起设置了一些仪表板和可视化对象,以监视由tomcat为我们的春季启动Web应用程序生成的accessLogs。

We set up some dashboards and visualisations with Kibana to monitor our accessLogs generated by tomcat for our spring boot web application.

我们特别关注具有以下内容的请求:答案是状态码5xx。

We specifically are paying attention to Requests that have been answered with Statuscode 5xx.

事实证明,如果客户端请求资源,并且在请求进行中,则取消请求(使用 ClientAbortException / BrokenPipe 错误),将ResponseCode设置为500,并且在应用程序日志中未记录任何错误(可以的)。

As it turns out, if a Client requests a Resource and while the request is ongoing cancels the request (with an ClientAbortException/BrokenPipe Error), the ResponseCode is set to 500 and no error is logged in the application logs (which is kind of okay).

我们现在希望将ResponseCode更改为不同于500的值,以更好地区分真实的内部服务器错误和由客户端启动的预期的连接中止。

We now wanted to change the ResponseCode to something different than 500, to better distinguish between "real" internal server errors, and "expected connection aborts, initiated by the client".

因此,我实现了如下的ExceptionHandler:

Therefor I implemented an ExceptionHandler as follows:

@RestControllerAdvice
public class HttpRequestExceptionHandler {

  private final static Logger LOGGER = LoggerFactory.getLogger(HttpRequestExceptionHandler.class);

  @ExceptionHandler(value = { ClientAbortException.class })
  @ResponseBody
  public ResponseEntity<String> exceptionHandler(Exception e, HttpServletResponse res) {
    res.setStatus(299);
    //res.sendError(299);
    LOGGER.error(""+res.getStatus());
    return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(null);
  }
}

事实证明,状态代码为500由tomcat / catalina / coyote内部实现,并且不能从外部更改(因为响应设置为commit)。

As it turns out though, the statusCode 500 is set by tomcat/catalina/coyote internals and can not be changed from outside (as the response is set to commited).

是否有可能以某种方式区分真实内部服务器错误和只是连接异常终止?

Is it possible to somehow distinguish between "real" internal server errors and "just" connection aborts?

推荐答案

事实证明,这似乎是在不久前与Tomcat一起引入的

As it turns out this seems to have been introduced not long ago, with Tomcat


8.5.12起

8.0.42起

7.0.76起

8.5.12 onwards
8.0.42 onwards
7.0.76 onwards

,计划是将其恢复为记录由应用程序设置的状态码,而不是500:请参见此处的讨论

and the plan is to revert it back to logging the statuscode that was set by the application, instead of 500: see discussion here.

另一种解决方法是将%{javax.servlet.error.exception} r 添加到访问日志模式服务er.tomcat.accesslog.pattern = 会注销类似的内容。

Another workaround might be to add %{javax.servlet.error.exception}r to the accesslog pattern server.tomcat.accesslog.pattern= which would log out something like..


... org。 apache.catalina.connector.ClientAbortException:
java.io.IOException:Eine bestehende Verbindung wurde ...

... org.apache.catalina.connector.ClientAbortException: java.io.IOException: Eine bestehende Verbindung wurde ...

并过滤通过ELK清除这些条目。

and filter out those entries through ELK.

这篇关于Tomcat Acces中的HTTP Statuscode 500登录ClientAbortException / BrokenPipe的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆