Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Didn't Dax add this to the sst layer at one point, which broken open-next?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did he ? He did it in the remix server in ion, and at the time i tried it in OpenNext as well ( to fix the 30s hanging issue ), but it ended up causing issue with ISR because of the pending promise ( at the time i didn't know that ).

Copy link
Contributor

Choose a reason for hiding this comment

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

I may have misremembered, but iirc he added that to the base SSR construct in sst. Things may be changed now, but it was many months ago.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're probably right actually, i thought you were talking about the remix stuff.
Anyway it works now

if ("type" in event) {
const result = await formatWarmerResponse(event);
responseStream.end(Buffer.from(JSON.stringify(result)), "utf-8");
Expand Down