Skip to content
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

Discarded requests whilst render worker process is restarting #53353

Closed
1 task done
NadhifRadityo opened this issue Jul 30, 2023 · 3 comments
Closed
1 task done

Discarded requests whilst render worker process is restarting #53353

NadhifRadityo opened this issue Jul 30, 2023 · 3 comments
Labels
bug Issue was opened via the bug report template. locked

Comments

@NadhifRadityo
Copy link

NadhifRadityo commented Jul 30, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.12.1
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant Packages:
      next: 13.4.13-canary.6
      eslint-config-next: 13.4.12
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/nextjs-discarded-requests-whilst-render-worker-process-is-restarting-y6vq47

To Reproduce

  1. Create an appDir API route that simulates a long request
// file: app/test/route.ts
import { NextRequest, NextResponse } from "next/server";

export const dynamic = "force-dynamic";

export async function GET(request: NextRequest) {
	await new Promise(res => setTimeout(res, 2000));
	return new NextResponse(`${Date.now()}`);
}
  1. Build and run the project.
npm run build && npm run start
  1. Flood the API routes with requests. In this case, I am using Apache benchmark, you could use Apache JMeter or curl with loops instead.
ab -n 100 -c 10 http://localhost:3000/test
  1. While it's still requesting, find the PID of the render worker and kill it. (I run npm run start in debug mode on VSCode so that I can see the PID tree directly)
taskkill /f /pid <PID>
  1. Errors logged out in the app console. Such as, but not limited to:
TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at async invokeRequest (E:\Projects\Web\nextsocketissue\node_modules\next\dist\server\lib\server-ipc\invoke-request.js:21:12)
    at async invokeRender (E:\Projects\Web\nextsocketissue\node_modules\next\dist\server\lib\router-server.js:226:29)
    at async handleRequest (E:\Projects\Web\nextsocketissue\node_modules\next\dist\server\lib\router-server.js:419:24)
    at async requestHandler (E:\Projects\Web\nextsocketissue\node_modules\next\dist\server\lib\router-server.js:436:13) {
  cause: Error: read ECONNRESET
      at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
    errno: -4077,
    code: 'ECONNRESET',
    syscall: 'read'
  }
}
Error: aborted
    at connResetException (node:internal/errors:717:14)
    at Socket.socketCloseListener (node:_http_client:455:19)
    at Socket.emit (node:events:523:35)
    at TCP.<anonymous> (node:net:335:12) {
  code: 'ECONNRESET'
}

Note:

  1. You may need to repeat step 3 multiple times before getting an error in the console. This step requires perfect timing between Apache benchmark requesting and you killing the render worker process.
  2. You also may get a different error message depending on which next.js version you use. I get a different one with next@latest and next@canary. But the error messages essentially say the same thing, ECONNRESET.

Describe the Bug

This bug is caused by the render worker restarting whilst it is still rendering the page. The restart mechanism works fine*, but it suffers when there is a request happening.

I originally discuss the issue in #51605 (#51605 (comment), #51605 (comment)), but figured it would be better creating a new one because I think this is a different problem.

Errors generated in this issue are also consistent with worker process restarting due to high memory usage. #49929 (comment)

* in my machine, with a small project. I noticed in a bigger project, sometimes the restart mechanism is broken, and I need to hard restart the whole app.

Expected Behavior

Next.js could rerender the request again after the render worker restarted, but this would not be possible if the response had already been sent partially. An easier solution would be to drop the request altogether and display an internal server error page instead.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

next start, locally

@NadhifRadityo NadhifRadityo added the bug Issue was opened via the bug report template. label Jul 30, 2023
@ThijsZijdel
Copy link

"next": "13.4.17",
Error appears after about 4-5 small dev file changes inside localhost and won't go away.
Removing .next and re-running start dev fixes it temporary.

TypeError: fetch failed
    at Object.fetch (node:internal/deps/undici/undici:11118:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async invokeRequest (../node_modules/.pnpm/next@13.4.17_@babel+core@7.22.10_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/server-ipc/invoke-request.js:17:12)
    at async invokeRender (../node_modules/.pnpm/next@13.4.17_@babel+core@7.22.10_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/router-server.js:253:29)
    at async handleRequest (../node_modules/.pnpm/next@13.4.17_@babel+core@7.22.10_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/router-server.js:446:24)
    at async requestHandler (../node_modules/.pnpm/next@13.4.17_@babel+core@7.22.10_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/router-server.js:463:13)
    at async Server.<anonymous> (../node_modules/.pnpm/next@13.4.17_@babel+core@7.22.10_react-dom@18.2.0_react@18.2.0/node_modules/next/dist/server/lib/start-server.js:117:13) {
  cause: Error: connect ECONNREFUSED ::1:50682
      at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
    errno: -61,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '::1',
    port: 50682
  }

Reverting back to "next": "13.4.13" removes the error fully.

@balazsorban44
Copy link
Member

Hi, we no longer rely on render workers (they got removed). Please upgrade to next@latest and open a new issue if you still experience this. Thank you!

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked
Projects
None yet
Development

No branches or pull requests

3 participants