spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.59k stars 38.13k forks source link

Setting spring.aot.enabled=true causes stack overflow #30684

Open yozaner1324 opened 1 year ago

yozaner1324 commented 1 year ago

I have a basic Spring Boot app using web and GemFire. When I run it with aot enabled, like this: java -Dspring.aot.enabled=true -jar build/libs/spring-native-experiment-1.0-SNAPSHOT.jar, it breaks, but when I disabled aot, like this: java -Dspring.aot.enabled=false -jar build/libs/spring-native-experiment-1.0-SNAPSHOT.jar, it runs as expected.

Spring Boot 3.0.7 GraalVM 17.0.7+8.1 MacOs 13.4 on an M1 Mac

Stack-trace:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'gemfireClusterSchemaObjectInitializer': Unsatisfied dependency expressed through method 'gemfireClusterSchemaObjectInitializer' parameter 1: Error creating bean with name 'gemfireCache': Instantiation of supplied bean failed
        at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArgument(BeanInstanceSupplier.java:315) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.aot.BeanInstanceSupplier.resolveArguments(BeanInstanceSupplier.java:258) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.aot.BeanInstanceSupplier.get(BeanInstanceSupplier.java:198) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.obtainInstanceFromSupplier(DefaultListableBeanFactory.java:947) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1214) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1158) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:560) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:520) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:973) ~[spring-beans-6.0.9.jar!/:6.0.9]
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:941) ~[spring-context-6.0.9.jar!/:6.0.9]
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:608) ~[spring-context-6.0.9.jar!/:6.0.9]
        at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:732) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:310) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1304) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java:1293) ~[spring-boot-3.0.7.jar!/:3.0.7]
        at org.example.MyApplication.main(MyApplication.java:28) ~[classes!/:1.0-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
        at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[spring-native-experiment-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:95) ~[spring-native-experiment-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[spring-native-experiment-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]
        at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65) ~[spring-native-experiment-1.0-SNAPSHOT.jar:1.0-SNAPSHOT]

The full stack trace is attached as a file because it was too long. Code to reproduce: https://github.com/yozaner1324/spring-native-experiment

Steps to reproduce:

  1. ./gradlew bootJar
  2. java -Dspring.aot.enabled=true -jar build/libs/spring-native-experiment-1.0-SNAPSHOT.jar

stackoverflow.txt

snicoll commented 1 year ago

Thanks for the report and for providing a sample. However, this doesn't build not for me:

> Could not get unknown property 'gemfireRepoUsername' for Credentials [username: null] of type org.gradle.internal.credentials.DefaultPasswordCredentials_Decorated.
spring-projects-issues commented 1 year ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

snicoll commented 1 year ago

I’ve been able to reproduce with additional instructions from the OP. I suspect that the CGLIB proxy and reentrant calls are leading to this. It isn’t a cycle per se as it stops before ending up in a StackOverflow.