rsnext/packages
Alexander Kachkaev 7076758c8d
Call res.write('') inside apiRes.redirect() helper to prevent an edge case (#20461)
This PR is a small follow-up to #14705. It saves Next.js users from falling into a [pretty nasty trap](https://github.com/nodejs/node/issues/36620) in which I ended up last Friday. It took more than two days to investigate what was going on, so I hope I'm the last person who’s doing it 😅

Next.js-specific MWE: https://github.com/kachkaev/hanging-response-in-next-via-redirect-plus-compression (needs to be ran locally using Node 14.0.0+).

> <img width="521" alt="Screenshot 2020-12-24 at 20 50 00" src="https://user-images.githubusercontent.com/608862/103105989-a9b8dc00-4629-11eb-9be3-5108755604bf.png">

To reproduce the bug I’m fixing:

1. Pick a large http body size (64 or 128 KB)
1. Check _Call res.end() after res.redirect() in /api/redirect_
1. Navigate to a heavy page or an api handler via redirect
1. Observe that the http response is never finished.

If you set `compress` to `false` in `next.config.js` or pick a small payload size (< `zlib.Z_DEFAULT_CHUNK` after compression), the bug will not be observed. This is explained by the use of `res.on("drain", ...)` [by the `compression` package](3fea81d0ea/index.js (L193-L218)). The package itself is not the reason for an issue though, it seems to be in the Node’s built-in `http` package.

I’m happy to provide more info or GitHub CI to the MWE if needed. I was also thinking of adding some Next.js-specific testing, but could not come up with a compact and clear test plan. Happy to do this if there are any ideas.

cc @botv (author of #14705)
2021-01-04 10:14:15 +00:00
..
create-next-app v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
eslint-plugin-next v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next Call res.write('') inside apiRes.redirect() helper to prevent an edge case (#20461) 2021-01-04 10:14:15 +00:00
next-bundle-analyzer v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-codemod v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-env v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-mdx v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-plugin-google-analytics v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-plugin-sentry v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-plugin-storybook v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-polyfill-module v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
next-polyfill-nomodule v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
react-dev-overlay v10.0.5-canary.8 2021-01-01 21:40:09 -05:00
react-refresh-utils v10.0.5-canary.8 2021-01-01 21:40:09 -05:00