joreilly / PeopleInSpaceGraphQLServer

Cloud Run based GraphQL backend for PeopleInSpace supporting queries and subscriptions
Apache License 2.0
5 stars 1 forks source link

Issue trying to deploy to docker #2

Closed rindress closed 2 years ago

rindress commented 2 years ago

Docker version: 4.5.0 (74594)

I am able to run ./gradlew bootRun successfully. Then I tried to build and run the docker image and I am getting a NoClassDefFound exception for HttpClient. Here is the output:

$ docker run -p8080:8080 peopleinspace-graphql
Setting Active Processor Count to 6
WARNING: Unable to convert memory limit "max" from path "/sys/fs/cgroup/memory.max" as int: memory size "max" does not match pattern "^([\\d]+)([kmgtKMGT]?)$"
Calculating JVM memory based on 1307828K available memory
Calculated JVM Memory Configuration: -XX:MaxDirectMemorySize=10M -Xmx887727K -XX:MaxMetaspaceSize=112900K -XX:ReservedCodeCacheSize=240M -Xss1M (Total Memory: 1307828K, Thread Count: 50, Loaded Class Count: 17519, Headroom: 0%)
Enabling Java Native Memory Tracking
Adding 128 container CA certificates to JVM truststore
Spring Cloud Bindings Enabled
Picked up JAVA_TOOL_OPTIONS: -Djava.security.properties=/layers/paketo-buildpacks_bellsoft-liberica/java-security-properties/java-security.properties -XX:+ExitOnOutOfMemoryError -XX:ActiveProcessorCount=6 -XX:MaxDirectMemorySize=10M -Xmx887727K -XX:MaxMetaspaceSize=112900K -XX:ReservedCodeCacheSize=240M -Xss1M -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+PrintNMTStatistics -Dorg.springframework.cloud.bindings.boot.enable=true

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v2.5.6)

2022-02-11 15:03:01.835  INFO 1 --- [           main] demo.DemoApplicationKt                   : Starting DemoApplicationKt using Java 1.8.0_322 on 057769dbf9a6 with PID 1 (/workspace/BOOT-INF/classes started by cnb in /workspace)
2022-02-11 15:03:01.837  INFO 1 --- [           main] demo.DemoApplicationKt                   : No active profile set, falling back to default profiles: default
2022-02-11 15:03:03.026  WARN 1 --- [           main] onfigReactiveWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'issPositionSubscription' defined in file [/workspace/BOOT-INF/classes/demo/IssPositionSubscription.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.IssPositionSubscription]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Ljava/net/http/HttpClient;
2022-02-11 15:03:03.041  INFO 1 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2022-02-11 15:03:03.065 ERROR 1 --- [           main] o.s.boot.SpringApplication               : Application run failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'issPositionSubscription' defined in file [/workspace/BOOT-INF/classes/demo/IssPositionSubscription.class]: Bean instantiation via constructor failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.IssPositionSubscription]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Ljava/net/http/HttpClient;
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:315) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:181) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1372) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1222) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:944) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.12.jar:5.3.12]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.12.jar:5.3.12]
    at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:64) ~[spring-boot-2.5.6.jar:2.5.6]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) [spring-boot-2.5.6.jar:2.5.6]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:434) [spring-boot-2.5.6.jar:2.5.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.5.6.jar:2.5.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1343) [spring-boot-2.5.6.jar:2.5.6]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1332) [spring-boot-2.5.6.jar:2.5.6]
    at demo.DemoApplicationKt.main(DemoApplication.kt:14) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_322]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_322]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_322]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_322]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) [workspace/:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:108) [workspace/:na]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) [workspace/:na]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) [workspace/:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [demo.IssPositionSubscription]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: Ljava/net/http/HttpClient;
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:117) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:311) ~[spring-beans-5.3.12.jar:5.3.12]
    ... 27 common frames omitted
Caused by: java.lang.NoClassDefFoundError: Ljava/net/http/HttpClient;
    at java.lang.Class.getDeclaredFields0(Native Method) ~[na:1.8.0_322]
    at java.lang.Class.privateGetDeclaredFields(Class.java:2583) ~[na:1.8.0_322]
    at java.lang.Class.getDeclaredField(Class.java:2068) ~[na:1.8.0_322]
    at java.util.concurrent.atomic.AtomicLongFieldUpdater$CASUpdater$1.run(AtomicLongFieldUpdater.java:388) ~[na:1.8.0_322]
    at java.util.concurrent.atomic.AtomicLongFieldUpdater$CASUpdater$1.run(AtomicLongFieldUpdater.java:386) ~[na:1.8.0_322]
    at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_322]
    at java.util.concurrent.atomic.AtomicLongFieldUpdater$CASUpdater.<init>(AtomicLongFieldUpdater.java:385) ~[na:1.8.0_322]
    at java.util.concurrent.atomic.AtomicLongFieldUpdater.newUpdater(AtomicLongFieldUpdater.java:89) ~[na:1.8.0_322]
    at io.ktor.client.engine.java.JavaHttpEngine.<clinit>(JavaHttpEngine.kt) ~[ktor-client-java-jvm-2.0.0-beta-1.jar:2.0.0-beta-1]
    at io.ktor.client.engine.java.Java.create(Java.kt:18) ~[ktor-client-java-jvm-2.0.0-beta-1.jar:2.0.0-beta-1]
    at io.ktor.client.HttpClientKt.HttpClient(HttpClient.kt:44) ~[ktor-client-core-jvm-2.0.0-beta-1.jar:2.0.0-beta-1]
    at demo.PeopleInSpaceApiKt.createHttpClient(PeopleInSpaceApi.kt:30) ~[classes/:na]
    at demo.PeopleInSpaceApi.<init>(PeopleInSpaceApi.kt:24) ~[classes/:na]
    at demo.PeopleInSpaceApi.<init>(PeopleInSpaceApi.kt:21) ~[classes/:na]
    at demo.IssPositionSubscription.<init>(IssPositionSubscription.kt:18) ~[classes/:na]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_322]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_322]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_322]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_322]
    at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41) ~[kotlin-reflect-1.6.10.jar:1.6.10-release-923(1.6.10)]
    at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108) ~[kotlin-reflect-1.6.10.jar:1.6.10-release-923(1.6.10)]
    at kotlin.reflect.jvm.internal.KCallableImpl.callDefaultMethod$kotlin_reflection(KCallableImpl.kt:159) ~[kotlin-reflect-1.6.10.jar:1.6.10-release-923(1.6.10)]
    at kotlin.reflect.jvm.internal.KCallableImpl.callBy(KCallableImpl.kt:112) ~[kotlin-reflect-1.6.10.jar:1.6.10-release-923(1.6.10)]
    at org.springframework.beans.BeanUtils$KotlinDelegate.instantiateClass(BeanUtils.java:867) ~[spring-beans-5.3.12.jar:5.3.12]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:196) ~[spring-beans-5.3.12.jar:5.3.12]
    ... 29 common frames omitted
Caused by: java.lang.ClassNotFoundException: java.net.http.HttpClient
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387) ~[na:1.8.0_322]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418) ~[na:1.8.0_322]
    at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:135) ~[workspace/:na]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351) ~[na:1.8.0_322]
    ... 54 common frames omitted

Native Memory Tracking:

Total: reserved=2374907KB, committed=333747KB
-                 Java Heap (reserved=888832KB, committed=135168KB)
                            (mmap: reserved=888832KB, committed=135168KB) 

-                     Class (reserved=1087360KB, committed=43136KB)
                            (classes #6418)
                            (malloc=8064KB #7972) 
                            (mmap: reserved=1079296KB, committed=35072KB) 

-                    Thread (reserved=17500KB, committed=17500KB)
                            (thread #17)
                            (stack: reserved=17428KB, committed=17428KB)
                            (malloc=55KB #102) 
                            (arena=17KB #31)

-                      Code (reserved=251258KB, committed=10566KB)
                            (malloc=1658KB #3298) 
                            (mmap: reserved=249600KB, committed=8908KB) 

-                        GC (reserved=40561KB, committed=37981KB)
                            (malloc=8081KB #176) 
                            (mmap: reserved=32480KB, committed=29900KB) 

-                  Compiler (reserved=20068KB, committed=20068KB)
                            (malloc=11KB #265) 
                            (arena=20057KB #17)

-                  Internal (reserved=8311KB, committed=8311KB)
                            (malloc=8279KB #9003) 
                            (mmap: reserved=32KB, committed=32KB) 

-                    Symbol (reserved=10029KB, committed=10029KB)
                            (malloc=8774KB #80024) 
                            (arena=1255KB #1)

-    Native Memory Tracking (reserved=1616KB, committed=1616KB)
                            (malloc=5KB #64) 
                            (tracking overhead=1611KB)

-               Arena Chunk (reserved=49371KB, committed=49371KB)
                            (malloc=49371KB) 
joreilly commented 2 years ago

Hi, thanks for the report. I just tried here and am seeing the same issue. I've mostly been running ./gradlew bootRun and deploying to Cloud Run so very possible I hadn't tested docker setup with latest code. This is heavily based on sample from https://github.com/GoogleCloudPlatform/kotlin-samples/blob/main/run/README.md though don't believe those use ktor client fwiw.

@jamesward just on the off chance that you've come across this before?

joreilly commented 2 years ago

hmm, could be related to version of JVM used...

joreilly commented 2 years ago

ok, not sure if this is cleanest or recommended way to do this but following seems to work here (added to build.gradle.kts)

tasks.getByName<org.springframework.boot.gradle.tasks.bundling.BootBuildImage>("bootBuildImage") {
    environment = mapOf("BP_JVM_VERSION" to "11.*")
}
rindress commented 2 years ago

Confirmed works here as well. Thanks!