Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Observation in ServerHttpObservationFilter is never stopped for asynchronous requests #32730

Open
wojtassi opened this issue Apr 29, 2024 · 0 comments
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on theme: observability An issue related to observability and tracing

Comments

@wojtassi
Copy link

Spring Framework 6.0.19
CometD 7.0.10
Micrometer 1.12.5

I'm not exactly sure which component is responsible for this issue but since spring-web contains ServerHttpObservationFilter, I am submitting this bug here.
We have recently run into a memory leak of DefaultLongTaskTimer$SampleImpl. This was introduced with micrometer introducing histograms for http.server.requests.active.

The leak happens only for requests to CometD and it happens because those requests are asynchronous.
In https://github.com/spring-projects/spring-framework/blob/main/spring-web/src/main/java/org/springframework/web/filter/ServerHttpObservationFilter.java:

  1. Observation is created at the start of doFilterInternal.
  2. In synchronous requests, Observation is closed at the end of that function.
  3. For asynchronous requests, Observation is never closed, by design, which was fine until histograms were introduced that use Observation.stop to stop DefaultLongTaskTimer$SampleImpl.
  4. Since Observation is never stopped, we end up with DefaultLongTaskTimer$SampleImpl leak

The problem is that there is no corresponding callback that would close the Observation once asynchronous requests completes.

Thanks,

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 29, 2024
@jhoeller jhoeller added in: web Issues in web modules (web, webmvc, webflux, websocket) theme: observability An issue related to observability and tracing labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: waiting-for-triage An issue we've not yet triaged or decided on theme: observability An issue related to observability and tracing
Projects
None yet
Development

No branches or pull requests

3 participants