Skip to content

fix(lambda): parse empty payload in lambda#600

Merged
hectorvent merged 1 commit intofloci-io:mainfrom
rhrlima:fix/lambda-empty-payload-parse
Apr 25, 2026
Merged

fix(lambda): parse empty payload in lambda#600
hectorvent merged 1 commit intofloci-io:mainfrom
rhrlima:fix/lambda-empty-payload-parse

Conversation

@rhrlima
Copy link
Copy Markdown
Contributor

@rhrlima rhrlima commented Apr 25, 2026

Summary

Fixes Lambda Invoke crashing the AWS Node.js managed runtime with
SyntaxError: Unexpected end of JSON input when the caller sends an
empty body. The /2018-06-01/runtime/invocation/next handler in
RuntimeApiServer now writes "{}" for both null and zero-length
payloads, matching real AWS Lambda behaviour.

Addresses: #599

Type of change

  • Bug fix (fix:)
  • New feature (feat:)
  • Breaking change (feat!: or fix!:)
  • Docs / chore

AWS Compatibility

Incorrect behaviour (before this PR): Any aws lambda invoke (or
internal invoker) that handed floci an empty body caused the managed
Node.js runtime to receive a zero-length response from
/runtime/invocation/next. The runtime then ran JSON.parse("") and
crashed before the user's handler executed, returning
{"errorType":"SyntaxError","errorMessage":"Unexpected end of JSON input", ...}
with FunctionError: Unhandled.

Root cause: the /next handler defaulted to "{}" only when
invocation.getPayload() == null. JAX-RS materialises a missing request
body as new byte[0], so the path silently sent "" to the runtime
instead of valid JSON.

Behaviour after this PR matches real AWS Lambda: invoke without
--payload causes the handler's event argument to be {}; handlers
that don't read event succeed unconditionally.

This is a Node.js-runtime symptom, but the fix sits in the runtime API
server and therefore covers every managed runtime that does
JSON.parse on the event body. No SDK or wire-format changes; the
fixture verified against the AWS CLI v2 wire protocol.

Changes

File Change
src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java The /next blockingHandler now treats null and zero-length payloads as "{}" so the runtime always receives valid JSON. Added an inline comment explaining the Node managed-runtime constraint that motivates this normalisation.
src/test/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServerTest.java New regression test nextEndpoint_emptyPayload_isDeliveredAsEmptyJsonObject enqueues a PendingInvocation whose payload is new byte[0], polls /next, and asserts the response body equals "{}". Without the fix, the assertion fails because the body is "".

Test plan

  • ./mvnw test -Dtest=RuntimeApiServerTest passes (verified locally; all six existing cases plus the new regression).
  • The new nextEndpoint_emptyPayload_isDeliveredAsEmptyJsonObject regression test fails before the fix (asserts body "{}", gets "") and passes after — confirming it pins the exact bug.
  • Manual end-to-end repro from the issue document: aws lambda invoke without --payload returns {"statusCode":200,"body":"ok"} after the fix instead of the JSON-parse SyntaxError.

Checklist

  • ./mvnw test passes locally
  • New or updated integration test added
  • Commit messages follow Conventional Commits

Copy link
Copy Markdown
Collaborator

@hectorvent hectorvent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @rhrlima,

Thanks

@hectorvent hectorvent merged commit 1b119fa into floci-io:main Apr 25, 2026
10 checks passed
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

Successfully merging this pull request may close these issues.

2 participants