Deploying to GAE Flex

Hi - we are using Vaadin 10 and trying to deploy to a Google App Engine Flex environment via a Docker container using a Tomcat runtime. Everything works fine when running the app via Spring’s bootRun, and also when I fire up the Docker container and connect to it. However, when we deploy to GAE the app seems to be constantly restarting or reloading when we click on links in the navigation sidebar. Any ideas on the following logs we are seeing?

Is this due to some session issue in Google App Engine Flex?

Sending xhr message to server: {“csrfToken”:“70dc1012-03f4-4942-be35-e4127053be35”,“rpc”:[{“type”:“mSync”,“node”:32,“feature”:1,“property”:“selected”,“value”:0},{“type”:“event”,“node”:32,“event”:“selected-changed”}]
,“syncId”:1,“clientId”:1}
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 Server visit took 85.8ms
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 JSON parsing took 0ms
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 Received xhr message: for(;;);[{“meta”:{“sessionExpired”:true}}]

VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:958 Response didn’t contain a server id. Please verify that the server is up-to-date and that the response data has not been modified in transmission.
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:974 Handling message from server
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:921 Handling dependencies
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 handleUIDLMessage: 0 ms
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 Setting heartbeat interval to -1sec.
VM748 client-BF4676DDAFDA5E40AE93EFEB692AAAD5.cache.js:189 Processing time was 5ms

17167317.log (3.3 KB)

We’re also going to be deploying into GAE at some point later this year - I’m curious to know if you’ve found a solution.

We have not found a solution yet. However, we have pinned the max instances for App Engine Flex to 1 and that seems to be working for us at the moment, until we have more time to invest in fixing this. We just modified the app.yml for the project to include the following:

automatic_scaling:
min_num_instances: 1
max_num_instances: 1

Like I said though, its not ideal, but bought us a bit of time.

As far as I know, Google AppEngine “Flex” with the “Java 8 Runtime” doesn’t support sessions (at the moment?).
See https://github.com/GoogleCloudPlatform/jetty-runtime/issues/242 to track the issue. Using “a single instance” is a hacky workaround: all requests are handled by the same instance, so everything seems to be fine.

A possible workaround would be using the Google AppEngine “Standard” variant (with Jetty and war-packaging).
You can then set “sessions-enabled” to true in “appengine-web.xml”, see https://cloud.google.com/appengine/docs/standard/java/config/appref

You can configure the build of a Spring-Boot based project to produce a war instead of a jar, so you can still use the power of Spring-Boot together with Vaadin, also when running in GAE (standard).

Just dicovered this
https://cloud.google.com/blog/products/application-development/introducing-websockets-support-for-app-engine-flexible-environment
and this
https://cloud.google.com/appengine/docs/flexible/java/using-websockets-and-session-affinity
(see bottom of this page)

It looks like in order to offer WebSockets on the GAE flex environment “they” implemented session-affinity

app.yaml:

network:
  session_affinity: true

It seems to work. Here is an example using Vaadin 13 with Spring Boot 2.1:
https://github.com/Petikoch/GoogleAppEngineSpringBootVaadinKotlinGradleExample-aka-GAESBVKGE

Peti Koch:
Just dicovered this
https://cloud.google.com/blog/products/application-development/introducing-websockets-support-for-app-engine-flexible-environment
and this
https://cloud.google.com/appengine/docs/flexible/java/using-websockets-and-session-affinity
(see bottom of this page)

It looks like in order to offer WebSockets on the GAE flex environment “they” implemented session-affinity

The page also says

“You should never use session affinity to build stateful applications.”

so be careful.

Thank you Olli Tietäväinen for the very important input.

I added a long “Caution” Block in https://github.com/Petikoch/GoogleAppEngineSpringBootVaadinKotlinGradleExample-aka-GAESBVKGE/blob/master/README.adoc regarding the topic of running a “server-side focused technology” like Vaadin in a “higly dynamic environment” like Google App Engine (flex) or Kubernetes.

Do you agree with this Caution block? Does it help others?

Best regards,
Peti

Looks good to me.