Skip to content

Commit

Permalink
fix lambda streaming hanging after return (#487)
Browse files Browse the repository at this point in the history
* fix lambda hanging after return

* Create lucky-ravens-teach.md
  • Loading branch information
conico974 authored Aug 20, 2024
1 parent c8d692b commit 8ddb621
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/lucky-ravens-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"open-next": patch
---

fix lambda streaming hanging after return
2 changes: 1 addition & 1 deletion packages/open-next/src/types/aws-lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface ResponseStream extends Writable {
type Handler = (
event: APIGatewayProxyEventV2,
responseStream: ResponseStream,
context?: Context,
context: Context,
) => Promise<any>;

interface Metadata {
Expand Down
7 changes: 6 additions & 1 deletion packages/open-next/src/wrappers/aws-lambda-streaming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,12 @@ function formatWarmerResponse(event: WarmerEvent) {

const handler: WrapperHandler = async (handler, converter) =>
awslambda.streamifyResponse(
async (event: AwsLambdaEvent, responseStream): Promise<AwsLambdaReturn> => {
async (
event: AwsLambdaEvent,
responseStream,
context,
): Promise<AwsLambdaReturn> => {
context.callbackWaitsForEmptyEventLoop = false;
if ("type" in event) {
const result = await formatWarmerResponse(event);
responseStream.end(Buffer.from(JSON.stringify(result)), "utf-8");
Expand Down

0 comments on commit 8ddb621

Please sign in to comment.