Add V2 streaming Lambda adapter and fix body-less 502 - #649
Draft
kieran-sf wants to merge 2 commits into
Draft
Conversation
Add createStreamingLambdaAdapterV2, a socket-intercept streaming Lambda adapter for MRT SSR. It drives an unmodified Node http.ServerResponse instead of monkey-patching it (better Express 4/5 compatibility), parses the raw HTTP wire bytes, and forwards them to the AWS response stream. It supports br/gzip/deflate compression with Accept-Encoding negotiation via the new StreamingCompressionConfig type. V1 remains the default. Also fix body-less streaming responses (302 redirects, 204/304, HEAD, bare res.end()) returning a 502 at the MRT edge. The AWS runtime emits the status/headers metadata prelude lazily, only just before the first write, so a response that ends without writing ships no prelude and the streaming edge cannot frame it. Both adapters now force a zero-length write before ending. Adds regression tests using a faithful RIC mock.
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
createStreamingLambdaAdapterV2, a new streaming Lambda adapter for MRT SSR that uses a socket-intercept design: it drives an unmodified Nodehttp.ServerResponseon a fakenet.Socket, parses the raw HTTP wire bytes, and forwards them to the AWS response stream. This avoids monkey-patchingServerResponse(as V1 does), improving compatibility with both Express 4 and 5. Supportsbr/gzip/deflateresponse compression withAccept-Encodingnegotiation via the newStreamingCompressionConfigtype. V1 remains the default.awslambda.HttpResponseStream.from) emits the status/headers metadata prelude lazily — only just before the first write to the stream. A response that reachesend()without ever writing (302 redirects, 204/304,HEAD, bareres.end()) ships with no prelude, so the streaming edge cannot frame it and returns its own 502InternalServerErrorExceptionregardless of the intended status code. Both adapters now force a zero-length write before ending the stream.Fix details
create-lambda-adapter.ts): adds a body-less branch inres.end()that callswriteChunk(Buffer.alloc(0)), which also flushes any active compressor.create-lambda-adapter-v2.ts): writes an empty string inonReceiveHead, which fires whenever the nativeServerResponseflushes its head (always, even for body-less responses).Testing
fromstub cannot catch this bug. Cases: bareres.end(), body-less redirect (asserts 302), 204 No Content, and body-less compressed.Changesets
@salesforce/mrt-utilitiesminor — V2 adapter.@salesforce/mrt-utilitiespatch — body-less 502 fix.