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

Nx + Next.js E2E target fails on GitHub Actions and creates "ghost" node processes #17395

Closed
2 of 4 tasks
andersonba opened this issue Jun 2, 2023 · 7 comments
Closed
2 of 4 tasks
Assignees
Labels
outdated scope: nextjs Issues related to NextJS support for Nx scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug

Comments

@andersonba
Copy link

andersonba commented Jun 2, 2023

Current Behavior

After updating Nx and NextJS to the latest versions, E2E tests consistently timeout on Github Actions. Also, "ghost" node processes persist post E2E tests, causing CPU usage spikes.

Expected Behavior

E2E tests should run successfully on Github Actions, without any lingering "ghost" processes causing CPU usage spikes.

GitHub Repo

No response

Steps to Reproduce

To check Github Actions failure:

  1. Just run nx affected --target e2e --parallel 1 --configuration e2e in workflow, e2e does not run successfully because the application does not go up in time.

To check "ghost" node processes:

  1. Set up an E2E app for a NextJS app in an Nx monorepo.
  2. Run nx affected --target e2e --parallel 1 --configuration e2e on the local environment.
  3. Observe that after the completion of the E2E tests, node processes remain active.

Nx Report

Node   : 18.15.0
   OS     : darwin arm64
   pnpm   : 7.32.0
   Hasher : Native

   nx                 : 16.3.1
   @nx/js             : 16.3.1
   @nx/jest           : 16.3.1
   @nx/linter         : 16.3.1
   @nx/workspace      : 16.3.1
   @nx/cypress        : 16.3.1
   @nx/devkit         : 16.3.1
   @nx/eslint-plugin  : 16.3.1
   @nx/nest           : 16.3.1
   @nx/next           : 16.3.1
   @nx/node           : 16.3.1
   @nx/plugin         : 16.3.1
   @nx/react          : 16.3.1
   @nx/rollup         : 16.3.1
   @nx/storybook      : 16.3.1
   @nx/vite           : 16.3.1
   @nx/web            : 16.3.1
   @nx/webpack        : 16.3.1
   nx-cloud           : 16.0.5
   typescript         : 5.0.4
   ---------------------------------------
   Community plugins:
   @nx-tools/nx-docker : 3.0.3
   ---------------------------------------
   Local workspace plugins:
         [our shared libraries omitted for company privacy]

Failure Logs

- ready started server on 0.0.0.0:4200, url: http://localhost:4200
[3830:0602/105303.380019:ERROR:gpu_memory_buffer_support_x11.cc(44)] dri3 extension not supported.

tput: No value for $TERM and no -T specified
====================================================================================================

  (Run Starting)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Cypress:        12.11.0                                                                        │
  │ Browser:        Electron 106 (headless)                                                        │
  │ Node Version:   v18.16.0 (/opt/hostedtoolcache/node/18.16.0/x64/bin/node)                      │
  │ Specs:          1 found (app.cy.ts)                                                            │
  │ Searched:       src/**/*.cy.{js,jsx,ts,tsx}                                                    │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


────────────────────────────────────────────────────────────────────────────────────────────────────
                                                                                                    
  Running:  app.cy.ts                                                                       (1 of 1)
Browserslist: caniuse-lite is outdated. Please run:
  npx browserslist@latest --update-db
  Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating


  sandbox
- event compiled client and server successfully in 21.9s (1622 modules)
- wait compiling...
- wait compiling / (client and server)...
    1) "before each" hook for "should display welcome message"


  0 passing (31s)
  1 failing

  1) sandbox
       "before each" hook for "should display welcome message":
     CypressError: `cy.visit()` failed trying to load:

http://localhost:4200/

We attempted to make an http request to this URL but the request failed without a response.

We received this error at the network level:

  > Error: ESOCKETTIMEDOUT

Common situations why this would fail:
  - you don't have internet access
  - you forgot to run / boot your web server
  - your web server isn't accessible
  - you have weird network configuration settings on your computer

Because this error occurred during a `before each` hook we are skipping the remaining tests in the current suite: `sandbox`
      at <unknown> (http://localhost:4200/__cypress/runner/cypress_runner.js:148084:82)
      at visitFailedByErr (http://localhost:4200/__cypress/runner/cypress_runner.js:147476:12)
      at <unknown> (http://localhost:4200/__cypress/runner/cypress_runner.js:148083:11)
      at tryCatcher (http://localhost:4200/__cypress/runner/cypress_runner.js:18744:23)
      at Promise._settlePromiseFromHandler (http://localhost:4200/__cypress/runner/cypress_runner.js:16679:31)
      at Promise._settlePromise (http://localhost:4200/__cypress/runner/cypress_runner.js:16736:18)
      at Promise._settlePromise0 (http://localhost:4200/__cypress/runner/cypress_runner.js:16781:10)
      at Promise._settlePromises (http://localhost:4200/__cypress/runner/cypress_runner.js:16857:18)
      at _drainQueueStep (http://localhost:4200/__cypress/runner/cypress_runner.js:13451:12)
      at _drainQueue (http://localhost:4200/__cypress/runner/cypress_runner.js:13444:9)
      at ../../node_modules/bluebird/js/release/async.js.Async._drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:13460:5)
      at Async.drainQueues (http://localhost:4200/__cypress/runner/cypress_runner.js:13330:14)
  From Your Spec Code:
      at Context.eval (webpack:///./src/e2e/app.cy.ts:3:0)
  
  From Node.js Internals:
    Error: ESOCKETTIMEDOUT
        at ClientRequest.<anonymous> (<embedded>:1956:73317)
        at Object.onceWrapper (node:events:641:28)
        at ClientRequest.emit (node:events:527:28)
        at Socket.emitRequestTimeout (node:_http_client:771:9)
        at Object.onceWrapper (node:events:641:28)
        at Socket.emit (node:events:539:35)
        at Socket._onTimeout (node:net:516:8)
        at listOnTimeout (node:internal/timers:559:17)
        at process.processTimers (node:internal/timers:502:7)
    From previous event:
        at q._onResolveUrl (<embedded>:4686:6886)
        at <unknown> (<embedded>:4686:67945)
    From previous event:
        at p.<anonymous> (<embedded>:4686:67641)
        at p.emit (node:events:527:28)
        at p.emitUntyped (<embedded>:4397:84346)
        at <unknown> (<embedded>:4397:91863)
        at process.processTicksAndRejections (node:internal/process/task_queues:78:11)




  (Results)

  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ Tests:        1                                                                                │
  │ Passing:      0                                                                                │
  │ Failing:      1                                                                                │
  │ Pending:      0                                                                                │
  │ Skipped:      0                                                                                │
  │ Screenshots:  1                                                                                │
  │ Video:        true
  │ Duration:     30 seconds                                                                       │
  │ Spec Ran:     app.cy.ts                                                                        │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘


  (Screenshots)

  -  /home/runner/work/web/web/dist/cypress/apps/sandbox-e2e/screenshots/app.cy.ts/sa     (1280x720)
     ndbox -- should display welcome message -- before each hook (failed).png                       


  (Video)

  -  Started processing:  Compressing to 32 CRF                                                     
- event compiled client and server successfully in 26.5s (1978 modules)
  -  Finished processing: 14 seconds                                                 

  -  Video output: /home/runner/work/web/web/dist/cypress/apps/sandbox-e2e/videos/app.cy.ts.mp4

    Compression progress:  100%

tput: No value for $TERM and no -T specified
====================================================================================================

  (Run Finished)


       Spec                                              Tests  Passing  Failing  Pending  Skipped  
  ┌────────────────────────────────────────────────────────────────────────────────────────────────┐
  │ ✖  app.cy.ts                                00:30        1        -        1        -        - │
  └────────────────────────────────────────────────────────────────────────────────────────────────┘
    ✖  1 of 1 failed (100%)                     00:30        1        -        1        -        -

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

I'm having issues with my Nx monorepo when running E2E tests on GitHub Actions. They consistently timeout on GitHub Actions but work fine locally.

Moreover, each E2E run spawns hanging node processes that do not terminate, increasing CPU usage significantly and slowing down my machine. These "ghost" processes appear only when E2E tests are run and persist even after the test execution ends.

I suspect these processes could be affecting the E2E test execution on GitHub Actions by consuming excessive resources.

Reference

Here's the link to the Slack thread where we began discussing this issue:
https://nrwlcommunity.slack.com/archives/C015WMB2A8P/p1685603562714809

Images

image
image
image
image

@barbados-clemens barbados-clemens added scope: nextjs Issues related to NextJS support for Nx scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx labels Jun 2, 2023
@barbados-clemens
Copy link
Contributor

at least partially related: vercel/next.js#45508

can confirm locally when running e2e jest-workers are orphaned, but running serve they are correctly killed.

unsure why as the .end() is called correctly in next dev server but seems like the process doesn't exit.
https://github.com/vercel/next.js/blob/canary/packages/next/src/server/dev/next-dev-server.ts#L1681

@BuddhiAbeyratne
Copy link

Hey I dont this jest-worker has anything to do with testing @barbados-clemens
as mentioned by @cjcheshire vercel/next.js#45508 (comment)

@barbados-clemens
Copy link
Contributor

@BuddhiAbeyratne the jest-workers are used when running the dev server for background processing, you can see them spin up when running serve. If they aren't supposed to be used then that would explain why they are probably sticking around when the dev server stops.

@jaysoo jaysoo self-assigned this Jun 6, 2023
@jaysoo
Copy link
Member

jaysoo commented Jun 6, 2023

@BuddhiAbeyratne Since this is a Next.js CLI issue and not an Nx one, I suggest watching that issue and adding additional info if you have any to provide.

For current workarounds, you can run pgrep -f "processChild.js" | xargs kill after each e2e run in CI for now to prevent the processes from hanging around. The other option is to downgrade to Next.js 13.1.x or 13.2.3 as the problem is introduced in later versions.

I think the timeout issue is related if the machine is running out of resources it could hang.

@jaysoo
Copy link
Member

jaysoo commented Jun 6, 2023

Going to close this issue, but if you think it is an Nx problem please re-open.

@jaysoo jaysoo closed this as completed Jun 6, 2023
@andersonba
Copy link
Author

I've just conducted another test: I updated Nx from version 16.2.1 (where this type of issue doesn't occur) to the latest version, 16.4.0, while retaining the same version of Next.

Upon executing the e2e target (run-many + parallel 1), I consistently encounter the same ESOCKETTIMEDOUT error. This suggests that the application either fails to start within the expected time frame, or the start process is unsuccessful.

I'm currently at a standstill with this issue, and I believe it's significant, given that Nx officially supports the Next framework. What steps can I take to assist in resolving this problem?

@jaysoo @barbados-clemens

@github-actions
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: nextjs Issues related to NextJS support for Nx scope: testing tools Issues related to Cypress / Jest / Playwright / Vitest support in Nx type: bug
Projects
None yet
Development

No branches or pull requests

4 participants