Skip to content

Web MVC metrics may have the wrong status when a filter throws an exception other than NestedServletException #27988

Closed
@tmachows

Description

@tmachows

Hi, I have a question, this might be a bug or maybe I don't know sth.
My question concerns these lines from WebMvcMetricsFilter class:

catch (NestedServletException ex) {
	response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
	record(timingContext, request, response, ex.getCause());
	throw ex;
}
catch (ServletException | IOException | RuntimeException ex) {
	record(timingContext, request, response, ex);
	throw ex;
}

Why for NestedServletException the response status is set to INTERNAL_SERVER_ERROR but for the latter exceptions (ServletException | IOException | RuntimeException) it is not?
I had a case where one of my custom filters was throwing I/O error (ResourceAccessException with IOException as a cause), resulting in 500 response from an endpoint, but in metrics it wasn't recorded with status 500, but rather with status 200 - because it got caught by the second catch clause.
Such behaviour may lead to incorrect metrics and undetected issues in applications.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions