Skip to content
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

SpringDelegatingLambdaContainerHandler unable to respond with rendered templates #858

Closed
mircohacker opened this issue Apr 23, 2024 · 10 comments
Assignees

Comments

@mircohacker
Copy link

mircohacker commented Apr 23, 2024

To help us debug your issue fill in the basic information below using the options provided

Serverless Java Container version: com.amazonaws.serverless:aws-serverless-java-container-springboot3:2.0.1

Implementations: Spring Boot

Framework version: org.springframework.boot:spring-boot-starter-web:3.2.4

Frontend service: HTTP API / HTML templates

Deployment method: SAM

Scenario

I want to render HTML (Apache freemarker) Templates within the lambda and send the rendered pages to the client.

Expected behavior

The rendered template is sent to the client.

Actual behavior

After the log messages indicate, that the templates are rendered, nothing happens till the lambda timeouts. This leads to an 500 response from the API Gateway.

Steps to reproduce

Run the sample for the alt-pet-store with these modifications in my fork. Call the link rendered by SAM or make a request for the rout /index

Side note: The old way as it is used in the pet-store sample (using a StreamLambdaHandler) works. You can see this when you apply the patch and deploy the pet-store sample.

Full log output

# Request to a route returning a template
2024-04-23T10:42:55.753Z  WARN 9 --- [           main] c.a.s.s.s.filter.CognitoIdentityFilter   : Cognito identity id in request is null
2024-04-23T10:42:55.772Z DEBUG 9 --- [           main] o.s.web.servlet.DispatcherServlet        : GET "/index", parameters={}
2024-04-23T10:42:55.839Z DEBUG 9 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.amazonaws.serverless.sample.springboot3.controller.IndexController#something2()
2024-04-23T10:42:55.892Z DEBUG 9 --- [           main] freemarker.cache                         : Couldn't find template in cache for "index.ftlh"("en", UTF-8, parsed); will try to load it.
2024-04-23T10:42:55.893Z DEBUG 9 --- [           main] o.s.ui.freemarker.SpringTemplateLoader   : Looking for FreeMarker template with name [index_en.ftlh]
2024-04-23T10:42:55.893Z DEBUG 9 --- [           main] freemarker.cache                         : TemplateLoader.findTemplateSource("index_en.ftlh"): Not found
2024-04-23T10:42:55.894Z DEBUG 9 --- [           main] o.s.ui.freemarker.SpringTemplateLoader   : Looking for FreeMarker template with name [index.ftlh]
2024-04-23T10:42:55.894Z DEBUG 9 --- [           main] freemarker.cache                         : TemplateLoader.findTemplateSource("index.ftlh"): Found
2024-04-23T10:42:55.894Z DEBUG 9 --- [           main] freemarker.cache                         : Loading template for "index.ftlh"("en", UTF-8, parsed) from "class path resource [templates/index.ftlh]"
2024-04-23T10:42:55.970Z DEBUG 9 --- [           main] o.s.w.s.view.freemarker.FreeMarkerView   : View name 'index', model
{}
2024-04-23T10:42:55.971Z DEBUG 9 --- [           main] o.s.w.s.view.freemarker.FreeMarkerView   : Rendering [index.ftlh]
2024-04-23T10:42:55.972Z DEBUG 9 --- [           main] freemarker.cache                         : "index.ftlh"("en", UTF-8, parsed) cached copy not yet stale; using cached.
2024-04-23T10:42:55.981Z DEBUG 9 --- [           main] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
2024-04-23T10:43:21.378Z 16464fa7-c762-4711-bd40-0e4bbaae72da Task timed out after 30.04 seconds


#Request to a route returning a response body
2024-04-23T10:43:32.672Z  WARN 7 --- [           main] c.a.s.s.s.filter.CognitoIdentityFilter   : Cognito identity id in request is null
2024-04-23T10:43:32.691Z DEBUG 7 --- [           main] o.s.web.servlet.DispatcherServlet        : GET "/pets", parameters={}
2024-04-23T10:43:32.758Z DEBUG 7 --- [           main] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.amazonaws.serverless.sample.springboot3.controller.PetsController#listPets(Optional, Principal)
2024-04-23T10:43:32.835Z DEBUG 7 --- [           main] m.m.a.RequestResponseBodyMethodProcessor : Using 'application/json', given [*/*] and supported [application/json, application/*+json]
2024-04-23T10:43:32.836Z DEBUG 7 --- [           main] m.m.a.RequestResponseBodyMethodProcessor : Writing [{com.amazonaws.serverless.sample.springboot3.model.Pet@6c372fe6, com.amazonaws.serverless.sample.spr (truncated)...]
2024-04-23T10:43:32.878Z DEBUG 7 --- [           main] c.a.s.p.i.s.AwsHttpServletResponse       : Response buffer flushed with 1136 bytes, latch=1
2024-04-23T10:43:32.879Z DEBUG 7 --- [           main] c.a.s.p.i.s.AwsHttpServletResponse       : Response buffer flushed with 1136 bytes, latch=0
2024-04-23T10:43:32.880Z DEBUG 7 --- [           main] c.a.s.p.i.s.AwsHttpServletResponse       : Response buffer flushed with 1136 bytes, latch=0
2024-04-23T10:43:32.881Z DEBUG 7 --- [           main] o.s.web.servlet.DispatcherServlet        : Completed 200 OK
END RequestId: 90b9a49e-5876-4935-9794-5f30fe1806dd
@olegz
Copy link
Collaborator

olegz commented Apr 25, 2024

There was an issue with s-c-function-serverless-web. It's been fixed and you can try it by manually upgrading to spring-cloud-function-serverless-web dependency version 4.1.2-SNAPSHOT.
I'll submit a PR here shortly for version upgrade as well

mircohacker added a commit to mircohacker/serverless-java-container that referenced this issue Apr 25, 2024
use spring-cloud-function-serverless-web:4.1.2-SNAPSHOT as advised in aws#858
@olegz
Copy link
Collaborator

olegz commented Apr 25, 2024

The PR was merged - 14abccf and function snapshot 4.1.2 is published as well, so technically you just need to use aws-serverless-java-container-springboot3:2.1.0-SNAPSHOT

@mircohacker
Copy link
Author

Hey @olegz sadly this does not fix the problem... Same symptoms as before

2024-04-25T18:09:10.268+02:00	2024-04-25T16:09:10.267Z DEBUG 8 --- [ main] freemarker.cache : "index.ftlh"("en", UTF-8, parsed) cached copy not yet stale; using cached.
2024-04-25T18:09:10.276+02:00	2024-04-25T16:09:10.276Z DEBUG 8 --- [ main] o.s.web.servlet.DispatcherServlet : Completed 200 OK
2024-04-25T18:09:35.532+02:00	2024-04-25T16:09:35.532Z 3b3d15d4-a588-4d31-9f34-7818c98b6c6c Task timed out after 30.03 seconds 

@olegz
Copy link
Collaborator

olegz commented Apr 25, 2024

Are you sure you get the latest snapshot from s-c-function? Can you try to delete it manually from local repo?
Here is what I am getting

ozhurakousY2V2K:mvc-aws ozhurakousky$ curl https://7ul7is7051.execute-api.us-east-2.amazonaws.com/index
<h1> hello from freemarker </h1>

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10

@olegz
Copy link
Collaborator

olegz commented Apr 25, 2024

Also, make sure you get it fro the right repo - https://repo.spring.io/libs-snapshot-local

@olegz
Copy link
Collaborator

olegz commented Apr 25, 2024

This Task timed out after 30.03 seconds tells me that you do not have the latest snapshot since it is the same
symptom that I have seen and is related to not flushing response buffer which is one of the fixes that i did

@mircohacker
Copy link
Author

My bad... After mvn install on the current main, i could use the new version in the samples (I have updated the reproducer).
It works 🎉 Thank you very much @olegz.
Can you give an estimate when the version 2.1.0 will be released?

@olegz
Copy link
Collaborator

olegz commented Apr 26, 2024

2.1.0 - That is up to AWS guys, I am just Spring ;) But keep playing with it and see if anything else needs fixing

@deki
Copy link
Collaborator

deki commented Apr 26, 2024

Hehe once a spring-cloud-function-serverless-web 4.1.2 release is available, I will be happy to create a 2.0.2 release. 2.1.0 will come somewhere mid/ end of May.

@mircohacker
Copy link
Author

Ok. Waiting for a fix to be released is easy in comparison to a fix being written 😉 Thank you both

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants