Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine, Spring Boot app keeps restarting

I am trying to build a Spring Boot REST API and host it on Google's App Engine. I prefer gradle in my projects at work, so I chose to use Gradle. The documentation is challenging to navigate.

I finally got the proper gradle file to work, and the proper app.yaml configuration. But my spring boot app just keeps restarting on App Engine. It automatically restarts regardless of any external influence (theres no errors when hitting an endpoint; the app works just like it should locally... for all of a few seconds).

I am having a very hard time debugging it.

Here are the last few logs before it restarts again. It looks like SpringFrameworkServlet is causing the issues and making it restart? Because I dont have any Servlets in my code, but im pretty sure App Engine has something with Servlets baked into its Java docker container.

A  2017-04-25 14:01:26.604  INFO 1 --- [           main] o.s.d.r.w.BasePathAwareHandlerMapping    : Mapped "{[/profile/{repository}],methods=[GET],produces=[application/schema+json]}" onto public org.springframework.http.HttpEntity<org.springframework.data.rest.webmvc.json.JsonSchema> org.springframework.data.rest.webmvc.RepositorySchemaController.schema(org.springframework.data.rest.webmvc.RootResourceInformation)

A  2017-04-25 14:01:27.362  INFO 1 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup

A  2017-04-25 14:01:28.937  INFO 1 --- [           main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)

A  2017-04-25 14:01:29.281  INFO 1 --- [           main] io.stevers.babli.BabliApplication        : Started BabliApplication in 34.136 seconds (JVM running for 39.899)

A  2017-04-25 14:01:30.978  INFO 1 --- [nio-8080-exec-9] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring FrameworkServlet 'dispatcherServlet'

A  2017-04-25 14:01:30.982  INFO 1 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization started

A  2017-04-25 14:01:31.126  INFO 1 --- [nio-8080-exec-9] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 144 ms

A  -XX:InitialHeapSize=514850816 -XX:MaxHeapSize=514850816 -XX:+ParallelRefProcEnabled -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC 

A  openjdk version "1.8.0_121"

A  OpenJDK Runtime Environment (build 1.8.0_121-8u121-b13-1~bpo8+1-b13)

A  OpenJDK 64-Bit Server VM (build 25.121-b13, mixed mode)

A  

A  

app.yaml

runtime: java
env: flex

service: springboot

runtime_config:  # Optional
  jdk: openjdk8

manual_scaling:
  instances: 1

build.gradle

buildscript {
    ext {
        springBootVersion = '1.5.3.BUILD-SNAPSHOT'
    }
    repositories {
        mavenCentral()
        maven { url "https://repo.spring.io/snapshot" }
        maven { url "https://repo.spring.io/milestone" }
    }
    dependencies {
        classpath('com.google.cloud.tools:appengine-gradle-plugin:1.3.0')
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'org.springframework.boot'
apply plugin: 'com.google.cloud.tools.appengine'

version = '1.0.0-SNAPSHOT'
sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
    mavenCentral()
    maven { url "https://repo.spring.io/snapshot" }
    maven { url "https://repo.spring.io/milestone" }
}


dependencies {
    compile('org.springframework.boot:spring-boot-starter-data-jpa')
    compile('org.springframework.boot:spring-boot-starter-jersey')
    compile('org.springframework.boot:spring-boot-starter-data-rest')
    compile('org.springframework.boot:spring-boot-starter-web')
    compile('com.h2database:h2')

    compile('org.springframework.boot:spring-boot-starter-thymeleaf')
    compile('org.webjars:bootstrap:3.3.6')
    testCompile('org.springframework.boot:spring-boot-starter-test')
}
like image 595
Stevers Avatar asked Apr 25 '17 14:04

Stevers


1 Answers

Thanks to the two github users, I identified my issue.

My server was restarting due to failing the health checks. When your service fails a health check, it is restarted. So the options for fixing this are as follows:

1) Disable health checks. Add this to your app.yaml

health_check:
  enable_health_check: False

2) Make sure your server returns a 200 or 404 for the /_ah/health end point. I added a simple REST Controller for that.

@RequestMapping("/_ah/health")
    public ResponseEntity<String> healthCheck() {
        return new ResponseEntity<>("Healthy", HttpStatus.OK);
    }

I hope this helps someone else! I got stuck for a day and a half on this :(.

like image 75
Stevers Avatar answered Oct 13 '22 20:10

Stevers