Description
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 22.1.0: Sun Oct 9 20:14:30 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T8103
Binaries:
Node: 20.3.0
npm: 9.6.7
Yarn: 1.22.19
pnpm: N/A
Relevant packages:
next: 13.4.7-canary.2
eslint-config-next: 13.4.6
react: 18.2.0
react-dom: 18.2.0
typescript: 5.1.3
Which area(s) of Next.js are affected? (leave empty if unsure)
Middleware / Edge (API routes, runtime), Standalone mode (output: "standalone")
Link to the code that reproduces this issue or a replay of the bug
npx create-next-app
To Reproduce
- Create a new app using
npx create-next-app@latest
- Run the app using
npx next dev
- Launch a browser and open the Network tab in the developer tools
- Navigate to http://localhost:3000
- In the Network tab, select the request for
localhost
and note that in the Response headersconnection: close
is listed. Select other requests and note the same header is sent for all responses. - Back in the terminal, Ctrl+C to stop the dev server
- Run
npx next build
to build the app, then runnpx next start
to run it - Back in the browser, refresh the page and observe that the same behavior is present once the app is built
Describe the Bug
The nodejs server created by Next.js, whether it be in dev mode, production mode after building, or production mode when standalone deployment is configured, returns a connection: close
response header to clients when rendering routes. This instructs the client to close the underlying TCP connection, rather than returning connection: keep-alive
which allows the client to reuse the TCP connection when making subsequent requests, greatly reducing latency. This behavior is leading to high latencies for server-rendered Next.js routes.
I reproduced this behavior on multiple machines, including OSX and Windows 11, on multiple versions of nodejs, including latest LTS and Current releases, using next 13.4.x and canary, with multiple browsers including Edge and Firefox.
Expected Behavior
The nodejs server created by Next.js should utilize HTTP 1.1 keep-alive to allow clients to keep TCP connections open.
Which browser are you using? (if relevant)
Edge, Firefox
How are you deploying your application? (if relevant)
next start