-
Notifications
You must be signed in to change notification settings - Fork 38.2k
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
Comments
We do manage async requests for many use cases with Spring MVC and WebFlux - We have not seen any leak for observations there. I have just checked with a simple application and I'm seeing observations being closed properly, and the The Can you share a minimal sample application that shows the problem? As we don't support CometD in our stack, please bear in mind that we can only justify spending time on a very minimal sample, ideally using an application generated on start.spring.io as a baseline. |
We are experiencing a very similar leak on a spring boot application configured to use jersey asynchronous requests. Can you have a look at the reproducer I pushed to https://github.com/fogninid/spring-framework-32730? On my machine a few minutes are sufficient to get a heap dump showing this memory leak: simply run While the test is running, you can also observe how the values of the |
Thanks @fogninid for reproducer. That saved me from carving out a sample from our production code.
This is the part that I did not understand. I just didn't see this behavior in the code for cometD and then I found this snippet: So it appears that this Observation mechanism does not work with jakarta.ws.rs annotations that returns AsyncResponse. |
For people that are running into this leak here is a bean that can be used to disable observations for specific endpoints:
based on this: This is specific to cometD but should be easily adaptable to other end points. |
Previously, our filter implementation was relying on the fact that async implementations would dispatch back to the container so that our filter would be executed again after the chain. It turns out that calling Thanks a lot for your helpful report @wojtassi @fogninid ! I will schedule this issue for the next maintenance release and backport the fix accordingly. |
Prior to this commit, the fix for spring-projectsgh-32730 disabled the involvment of the osbervation filter for async dispatches. Instead of relying on ASYNC dispatches to close the observation for async requests, this is now using an async listener instead: async dispatches are not guaranteed to happen once the async request is handled. This change caused another side-effect: because async dispatches are not considered anymore by this filter, the observation scope is not reinstated for async dispatches. For example, `ResponseBodyAdvice` implementations do not have the observation scope opened during their execution. This commit re-enables async dispatches for this filter, but ensures that observations are not closed during such dispatches as this will be done by the async listener. Fixes spring-projectsgh-33091
Prior to this commit, the fix for gh-32730 disabled the involvment of the osbervation filter for async dispatches. Instead of relying on ASYNC dispatches to close the observation for async requests, this is now using an async listener instead: async dispatches are not guaranteed to happen once the async request is handled. This change caused another side-effect: because async dispatches are not considered anymore by this filter, the observation scope is not reinstated for async dispatches. For example, `ResponseBodyAdvice` implementations do not have the observation scope opened during their execution. This commit re-enables async dispatches for this filter, but ensures that observations are not closed during such dispatches as this will be done by the async listener. Fixes gh-33091
Prior to this commit, the fix for gh-32730 disabled the involvment of the osbervation filter for async dispatches. Instead of relying on ASYNC dispatches to close the observation for async requests, this is now using an async listener instead: async dispatches are not guaranteed to happen once the async request is handled. This change caused another side-effect: because async dispatches are not considered anymore by this filter, the observation scope is not reinstated for async dispatches. For example, `ResponseBodyAdvice` implementations do not have the observation scope opened during their execution. This commit re-enables async dispatches for this filter, but ensures that observations are not closed during such dispatches as this will be done by the async listener. Fixes gh-33128
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:
The problem is that there is no corresponding callback that would close the Observation once asynchronous requests completes.
Thanks,
The text was updated successfully, but these errors were encountered: