Skip to content

fix(dev-overrides): Add automatic response cleanup via onClose callback #952

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sommeeeer
Copy link
Contributor

@sommeeeer sommeeeer commented Aug 7, 2025

To make request.signal.onabort work in route handlers. Currently only works for node and express-dev. It will close the OpenNextNodeResponse we pass into NextServer's request handler when the original response in the wrapper is closed. This will ensure that the AbortSignal associated with request.signal is properly triggered when a client disconnects during a streaming response.

I did try to get it to work with awsLambda.streamifyResponse. It looks like we get no event emitted on responseStream when a client disconnects. I even tried with a barebone Lambda like this:

exports.handler = awslambda.streamifyResponse(
    async (event, responseStream, context) => {
        responseStream.setContentType('text/event-stream')
        responseStream.on("close", ()=> {
          // this never gets emitted at any point of time
          console.log("responseStream closed");
        });
        for (let i = 0; i < 20; i++) {
            await sleep(1000);
            responseStream.write(`event: ping\n`);
            responseStream.write(`data: ${i}\n\n`);
        }
        responseStream.end();
    }
);

Copy link

changeset-bot bot commented Aug 7, 2025

🦋 Changeset detected

Latest commit: 81294d0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@opennextjs/aws Patch
app-pages-router Patch
app-router Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

pkg-pr-new bot commented Aug 7, 2025

Open in StackBlitz

pnpm add https://pkg.pr.new/@opennextjs/aws@952

commit: 81294d0

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.

1 participant