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

Memory increases with 3.2.3 #39838

Closed
clucca-gb opened this issue Mar 5, 2024 · 13 comments
Closed

Memory increases with 3.2.3 #39838

clucca-gb opened this issue Mar 5, 2024 · 13 comments
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid

Comments

@clucca-gb
Copy link

clucca-gb commented Mar 5, 2024

After migrating 3.2.2 to 3.2.3, in our apis memory started to rise until the pods fell:

Captura de Tela 2024-03-06 às 10 35 25

With 3.2.2:

Captura de Tela 2024-03-06 às 10 35 34

In our tests it appears to be a problem related to aws.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 5, 2024
@wilkinsona
Copy link
Member

Thanks for the report. Unfortunately, without some more information we won't be able to diagnose the problem. It looks like your application contains a memory leak. I find that the best way to analyse a memory leak is by taking a series of heap dumps and then compare them looking for an increasing number of a particular type of object being retained in the heap.

Due to the risk of a heap dump containing secrets, such analysis is often best done by you. Alternatively, if you're confident that the heap does not contain any information that should not be public, you could share them with us here and we can take a look.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Mar 5, 2024
@bclozel
Copy link
Member

bclozel commented Mar 5, 2024

In our tests it appears to be a problem related to aws.

What do you mean? Do you have data showing more memory consumed by Spring Boot classes? Did you attach a memory profiler to the application?

Please provide more information - right now this report isn't actionable for us.

@clucca-gb
Copy link
Author

Thanks for the answer.
We are trying to find more detailed information about this issue.

@clucca-gb
Copy link
Author

Regarding what I said about AWS, we noticed that only in apis we use spring-cloud-aws (latest version 3.1.0) this problem occurred with the springboot update.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 6, 2024
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 6, 2024
@clucca-gb
Copy link
Author

clucca-gb commented Mar 6, 2024

Hello!
I came back here with more details.
Under analysis with the new relic observability tool:
image
The class with the possible problem was identified:
image
with the help of Heapdump tool we compared both versions and found this scenario:

v3.3.2
image
v3.3.3
image
Captura de Tela 2024-03-06 às 14 56 11

using eclipse memory analyser:

image

image

image

image

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 6, 2024
@wfcosta
Copy link

wfcosta commented Mar 6, 2024

Please focus analysis on Problem Suspect 3 of undertow. We thing it this item.

@wilkinsona
Copy link
Member

Thanks for the additional details. Spring Boot 3.2.3 upgraded to Undertow 2.3.12.Final. I suspect that it contains a regression that is causing the memory leak. Please try using Spring Boot 3.2.3 with Undertow downgraded to 2.3.10.Final which is the version used by Spring Boot 3.2.2. You may also want to try Undertow 2.3.11.Final to narrow things down further.

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 6, 2024
@Tythor
Copy link

Tythor commented Mar 7, 2024

Hi @clucca-gb, are you passing in an executor to the Undertow servlet like this?

@Bean
public UndertowDeploymentInfoCustomizer undertowDeploymentInfoCustomizer() {
   return deploymentInfo -> deploymentInfo.setExecutor(new CustomExecutor());
}

Using Undertow in the default configuration did not cause problems for me until I switched to using a different executor.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 7, 2024
@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Mar 7, 2024
@clucca-gb
Copy link
Author

@Tythor Hello!
Yeah, it is!
I'll try to understand if it's possible to remove it.

@clucca-gb
Copy link
Author

clucca-gb commented Mar 8, 2024

By the way, we changed Undertown versions to the suggested ones and Memory Leak no longer occurred anymore!


<dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>
        <dependency>
            <groupId>io.undertow</groupId>
            <artifactId>undertow-core</artifactId>
            <version>2.3.10.Final</version>
        </dependency>
        <dependency>
            <groupId>io.undertow</groupId>
            <artifactId>undertow-servlet</artifactId>
            <version>2.3.10.Final</version>
        </dependency>
        <dependency>
            <groupId>io.undertow</groupId>
            <artifactId>undertow-websockets-jsr</artifactId>
            <version>2.3.10.Final</version>
        </dependency>
    <dependency>

Captura de Tela 2024-03-08 às 15 55 09

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Mar 8, 2024
@zhlian94
Copy link

zhlian94 commented Mar 8, 2024

Hi,
I would like to add on my finding from my tech stack.

  1. leaking happened to server threads, as many as 200 (display one hundred, and boots default allow 200 as max). these server threads are managing the POST requests “/instances” from API services.

image

  1. these leaking threads lock memory and shown as memory leaks but not root cause indeed, if you see this leaking memory such as Byte objects leak(biggest), HttpClient leak, NioEndpoint leak.

image

  1. Use Dynatrace profiling tool to check memory allocation, first check ThreadPoolExecutor pool, look for CloseableHTTPClient.execute, I could not find them visually

image

  1. continue to check FastThreadLocalRunnable which is referenced by each worker in ThreadPoolExcutor above, I could not find CloseableHTTPClient.execute either.

image

  1. Given FastThreadLocalRunnable worker to manage all concurrent threads and the parallel threads are self-managed, who are going to manage the server threads in ThreadPoolExecutor? Given the finding that no CloseableHTTPClient is implemented, any leftover in thread local could make the server threads leak. Or If CloseableHTTPClient is implemented, how to manage reference from server worker to FastThreadLocalRunnable pool? Seems the thread leaks involved a dilemma in design and not resolved and leave it as leak hole.
    Hope these feedbacks help designers and help to resolve the leak quicker.
    I intend to disable POST on boots server threads to stop thread leaking as temporary solution. I would like to hear your opinions.
    Regards

@wilkinsona
Copy link
Member

That's good news. Thanks, @clucca-gb. Please open an Undertow issue so that they can investigate why configuring a custom executor as you have done now causes a memory leak. I'll close this issue for now as I don't think there's anything we can do about this in Spring Boot.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Mar 9, 2024
@wilkinsona wilkinsona added status: invalid An issue that we don't feel is valid for: external-project For an external project and not something we can fix and removed status: waiting-for-triage An issue we've not yet triaged status: feedback-provided Feedback has been provided labels Mar 9, 2024
@wilkinsona
Copy link
Member

@zhlian94 your problem appears to be unrelated. As far as I tell you're using Tomcat, not Undertow, and are perhaps using a Reactor Netty based WebClient too. If you'd like some help investigating why your application appears to be leaking memory, please ask on Stack Overflow to begin with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project For an external project and not something we can fix status: invalid An issue that we don't feel is valid
Projects
None yet
Development

No branches or pull requests

7 participants