fix(lambda): parse empty payload in lambda#600
Merged
hectorvent merged 1 commit intofloci-io:mainfrom Apr 25, 2026
Merged
Conversation
hectorvent
approved these changes
Apr 25, 2026
Collaborator
hectorvent
left a comment
There was a problem hiding this comment.
Great catch @rhrlima,
Thanks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes Lambda Invoke crashing the AWS Node.js managed runtime with
SyntaxError: Unexpected end of JSON inputwhen the caller sends anempty body. The
/2018-06-01/runtime/invocation/nexthandler inRuntimeApiServernow writes"{}"for bothnulland zero-lengthpayloads, matching real AWS Lambda behaviour.
Addresses: #599
Type of change
fix:)feat:)feat!:orfix!:)AWS Compatibility
Incorrect behaviour (before this PR): Any
aws lambda invoke(orinternal 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 ranJSON.parse("")andcrashed before the user's handler executed, returning
{"errorType":"SyntaxError","errorMessage":"Unexpected end of JSON input", ...}with
FunctionError: Unhandled.Root cause: the
/nexthandler defaulted to"{}"only wheninvocation.getPayload() == null. JAX-RS materialises a missing requestbody as
new byte[0], so the path silently sent""to the runtimeinstead of valid JSON.
Behaviour after this PR matches real AWS Lambda: invoke without
--payloadcauses the handler'seventargument to be{}; handlersthat don't read
eventsucceed 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.parseon the event body. No SDK or wire-format changes; thefixture verified against the AWS CLI v2 wire protocol.
Changes
src/main/java/io/github/hectorvent/floci/services/lambda/runtime/RuntimeApiServer.java/nextblockingHandlernow treatsnulland 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.javanextEndpoint_emptyPayload_isDeliveredAsEmptyJsonObjectenqueues aPendingInvocationwhose payload isnew 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=RuntimeApiServerTestpasses (verified locally; all six existing cases plus the new regression).nextEndpoint_emptyPayload_isDeliveredAsEmptyJsonObjectregression test fails before the fix (asserts body"{}", gets"") and passes after — confirming it pins the exact bug.aws lambda invokewithout--payloadreturns{"statusCode":200,"body":"ok"}after the fix instead of the JSON-parseSyntaxError.Checklist
./mvnw testpasses locally