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

[GraalVM] Jackson serialisation test gives false positive for AWS Lambda #41350

Closed
DudekJakub opened this issue Jun 21, 2024 · 3 comments
Closed
Labels
area/amazon-lambda area/jackson Issues related to Jackson (JSON library) area/kotlin area/native-image kind/bug Something isn't working triage/invalid This doesn't seem right

Comments

@DudekJakub
Copy link

DudekJakub commented Jun 21, 2024

Describe the bug

Hello everyone.

I would like to report unexpected behaviour when running my quarkus native lambda on AWS and how testing in native mode gives me probably false positive results (not sure at this point if it is issue on GraalVM side which I use for native compilation or AWS environment and how I run my lambda there).

Expected behavior

When you check provided reproducer you will see:

  1. Lambda class LambdaEndToEnd test class.

  2. In Lambda.class here is handleRequest function which looks like that:

    override fun handleRequest(event: Any, context: Context): String {
        logger.info { "Triggering native serialization" }
        val serializedValue = ObjectMapper().writeValueAsString(listOf(TestData("Data")))
        logger.info { "Processed with serializedValue=$serializedValue" }
        if (serializedValue != """[{"data":"Data"}]""") {
            throw IllegalArgumentException("Native serialization doesn't work!")
        }
        return serializedValue
    } 
    

This method is supposed to use ObjectMapper (no custom configuration provided, all default) to serialize given value.
The result should be json format [{"data":"Data"}]

  1. In LambdaEndToEnd.class there is basic and simple test to check above function's behaviour (running with @QuarkusTest).
  2. In LambdaEndToEndNative.class there is @QuarkusIntegrationTest for native testing.
  3. Expected behaviour is simple -> serializedValue should always equals [{"data":"Data"}] either using JVM, GraalVM or running it on AWS environment.

Actual behavior

Unfortunately when I run my lambda on AWS then serializedValue is always [{}], unless I annotate TestData.class (which is being serialized) with @RegisterForReflection (from io.quarkus.runtime.annotations) whereas it is not required whenever I run test either with JVM or natively using GraalVM.

So in nutshell, outside of AWS environment (basic config info below) serialisation doesn't work as expected but when JVM or GraalVM is used then everything is fine (even without @RegisterForReflection set anywhere).

I do not understand where is the issue located. Is it unexpected "native" behaviour when testing serialisation with GraalVM or there is something wrong on AWS side?

How to Reproduce?

  1. Download reproducer from https://github.com/DudekJakub/test-quarkus-native-graalvm-lambda
  2. Run test LambdaEndToEnd.class with JVM -> OK
  3. Run test with GraalVM (natively) by using ./gradlew clean quarkusIntTest -> OK
  4. Deploy lambda on AWS and run "test" on lambda -> IllegalArgumentException("Native serialization doesn't work!") is being thrown -> serializedValue unexpectedly equals [{}]

Below two screenshots from AWS:

This one shows result from CloudWatch logs when lambda is run
screenshot1

This shows lambda configuration
screenshot2

Output of java -version

OpenJDK Runtime Environment Corretto-17.0.9.8.1 (build 17.0.9+8-LTS)

Mandrel or GraalVM version (if different from Java)

GraalVM version 21.0.1

Quarkus version or git rev

3.10.1

Build tool (ie. output of mvnw --version or gradlew --version)

Gradle 8.5

Additional information

Kotlin: 1.9.20
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.9 (Amazon.com Inc. 17.0.9+8-LTS)
OS: Mac OS X 13.5 aarch64

@DudekJakub DudekJakub added area/native-image kind/bug Something isn't working labels Jun 21, 2024
@quarkus-bot quarkus-bot bot added area/amazon-lambda area/jackson Issues related to Jackson (JSON library) area/kotlin labels Jun 21, 2024
Copy link

quarkus-bot bot commented Jun 21, 2024

/cc @Karm (mandrel), @galderz (mandrel), @geoand (jackson,kotlin), @gsmet (jackson), @matejvasek (amazon-lambda), @patriot1burke (amazon-lambda), @zakkak (mandrel)

@galderz
Copy link
Member

galderz commented Jun 21, 2024

This looks slightly related to #39934

@geoand
Copy link
Contributor

geoand commented Jun 25, 2024

The fact that it works in GraalVM without needing @RegisterForReflection on TestData is pure luck.

In general, for a class to be registered automatically for reflection, it needs to be part of the signature of "known" methods or classes - having it simply in the method body of a random method is not good enough.

@geoand geoand closed this as not planned Won't fix, can't repro, duplicate, stale Jun 25, 2024
@geoand geoand added the triage/invalid This doesn't seem right label Jun 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/amazon-lambda area/jackson Issues related to Jackson (JSON library) area/kotlin area/native-image kind/bug Something isn't working triage/invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

3 participants