Skip to content

memory leak problem about redirect #13771

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

Closed
walkerzhao opened this issue Jul 14, 2018 · 6 comments
Closed

memory leak problem about redirect #13771

walkerzhao opened this issue Jul 14, 2018 · 6 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

@walkerzhao
Copy link

walkerzhao commented Jul 14, 2018

our team has a memory leak problem lately.
I have dump the heap and found that there are many strings in the heap. the strings is something about redirect string. So we reproduce the problem by the following demo project: https://github.com/zhao41654828/springstudy/tree/master/service-hi

controller adress: https://github.com/zhao41654828/springstudy/blob/master/service-hi/src/main/java/com/forezp/web/MiniProgramController.java

Debug the program by sending a request:127.0.0.1:8763/web/testRedirect1
we can find that it run into like this:
image

In the AbstractAutoProxyCreator class, the advisedBeans don't have number limit, the ConcurrentHashMap will have a lot of objects.

I want to know this is whether or not a bug in springmvc. If not, I want to know the reason and how can I to avoid it.
Now i do like this to avoid it.

	/**
	 * @param
	 * @return
	 */
	@RequestMapping("/testRedirect1")
	public void getTest2(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String redirectUrl =  "http://www.baidu.com";
		Random random = new Random();
		int data = random.nextInt(21_0000_0000);
		redirectUrl = redirectUrl + "/" + data;
		resp.sendRedirect(redirectUrl);
	}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 14, 2018
@wilkinsona
Copy link
Member

wilkinsona commented Jul 15, 2018

Thanks for the sample. You are using Spring Boot 1.4.2 which is no longer supported. You are also using a mixture of versions of Spring Framework modules (4.3.4.RELEASE and 4.3.9.RELEASE) and of Spring Cloud modules. Please update your dependency versions to use supported versions (the latest Spring Boot 1.5.x, for example) and see if the problem remains. If it does, we'll happily take a look at an updated sample.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Jul 15, 2018
@walkerzhao
Copy link
Author

I have update 1.4.2 to 1.5.7 version.
The proram is still into the adviceBeans map like this:
springboot_1_5_7

@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 Jul 15, 2018
@wilkinsona
Copy link
Member

Thanks, but 1.5.7 isn’t the latest 1.5.x version. Please upgrade Spring Boot to 1.5.14 and all your other dependencies to their matching latest version.

@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 Jul 15, 2018
@walkerzhao
Copy link
Author

I have try 1.5.14, the result is still as before.
springboot_1_5_14

@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 Jul 16, 2018
@wilkinsona
Copy link
Member

wilkinsona commented Jul 16, 2018

Thanks. There are still some problems with your dependencies (mixing Spring Cloud versions, for example) but I don't think they're causing the problem you're seeing. You can reproduce your problem with Spring Boot 1.5.14, dependencies on spring-boot-starter-web and spring-boot-starter-aop, and this minimal application:

package com.example.demo;

import java.util.UUID;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@SpringBootApplication
@EnableAspectJAutoProxy
public class Gh13771Application {

	public static void main(String[] args) {
		SpringApplication.run(Gh13771Application.class, args);
	}

	@Controller
	public static class RedirectController {

		@RequestMapping("/")
		public String redirect() {
			return "redirect:/example/" + UUID.randomUUID();
		}
		
	}

}

The problem is that InternalResourceViewResolver calls AutowireCapableBeanFactory.initializeBean(Object existingBean, String beanName) using the complete URL as the beanName. The bean name is then used by AbstractAutoProxyCreator.wrapIfNecessary(Object, String, Object) as the key when it caches the fact that no advice applies to it. This feels like a bug to me, but it will have to be addressed in Spring Framework as it is out of Boot's control. I've opened SPR-17045.

@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: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Jul 16, 2018
@walkerzhao
Copy link
Author

Thanks.
I searched the spr and found that someone has reported before:
https://jira.spring.io/browse/SPR-15220?jql=text%20~%20%22AbstractAutoProxyCreator%20memory%22

But the Spring Framewok may think that to make the beanname to be the same is a better solution.
I hope they can notice this problem and give some solutions.

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

3 participants