Skip to content

Next.js server returns connection: close header for all routes #51592

Closed as not planned
@DamianEdwards

Description

@DamianEdwards

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

  1. Create a new app using npx create-next-app@latest
  2. Run the app using npx next dev
  3. Launch a browser and open the Network tab in the developer tools
  4. Navigate to http://localhost:3000
  5. In the Network tab, select the request for localhost and note that in the Response headers connection: close is listed. Select other requests and note the same header is sent for all responses.
  6. Back in the terminal, Ctrl+C to stop the dev server
  7. Run npx next build to build the app, then run npx next start to run it
  8. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    OutputRelated to the the output configuration option.RuntimeRelated to Node.js or Edge Runtime with Next.js.bugIssue was opened via the bug report template.lockedstaleThe issue has not seen recent activity.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions