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

🐛 Bug: infinite loop in parallel tests with uncaught error containing circular dependency #5209

Open
3 of 4 tasks
mathewzile opened this issue Sep 5, 2024 · 1 comment · May be fixed by #5212
Open
3 of 4 tasks
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@mathewzile
Copy link

mathewzile commented Sep 5, 2024

Bug Report Checklist

  • I have read and agree to Mocha's Code of Conduct and Contributing Guidelines
  • I have searched for related issues and issues with the faq label, but none matched my issue.
  • I have 'smoke tested' the code to be tested by running it outside the real test suite to get a better sense of whether the problem is in the code under test, my usage of Mocha, or Mocha itself.
  • I want to provide a PR to resolve this

Expected

Test should report uncaught error (even with circular dependency) as failure and stop execution.

Actual

Test runs in infinite loop until configured timeout.

Minimal, Reproducible Example

describe("Test", () => {
  it("throw circular dependency error object", async () => {
    const errorA = {};
    const objectB = {toA: errorA};
    errorA.toB = objectB;
    
    const d = new Error();
    d.error = errorA;
    throw d;
  });
});
  1. Run npx mocha not in parallel mode, output is correct:
  Test
    1) throw circular dependency error object


  0 passing (7ms)
  1 failing

  1) Test
       throw circular dependency error object:

  Error
      at Context.<anonymous> (test\asset-design-service.test.js:7:15)
      at processImmediate (node:internal/timers:483:21)
  1. Run npx mocha --parallel, infinite loop happens (nothing in console)

Versions

mocha: 10.7.3
node: v20.16.0

Additional Info

Issue is introduced in this commit: d7013dd which changed the passed object to breakCircularDeps

Using v10.7.0, the uncaught error is reported correctly in parallel mode:

  Test
    1) throw circular dependency error object


  0 passing (858ms)
  1 failing

  1) Test
       throw circular dependency error object:

  Error
      at Context.<anonymous> (test\asset-design-service.test.js:7:15)
      at processImmediate (node:internal/timers:483:21)

In my actual project, this pairs array grows infinitely as a result of the circular dependency:

Image

@mathewzile mathewzile added status: in triage a maintainer should (re-)triage (review) this issue type: bug a defect, confirmed by a maintainer labels Sep 5, 2024
@geoffcorey
Copy link

I am seeing the same thing with

Mocha: 10.7.3
Node: 20.11.1

At the end of a parallel test run it hangs. This does not matter if being run by Instanbul or not. I do have --require mochawesome/register and have not tried running without it but it appears what was stated in the bug seems to be unrelated to mochawesome.

@JoshuaKGoldberg JoshuaKGoldberg added status: accepting prs Mocha can use your help with this one! and removed status: in triage a maintainer should (re-)triage (review) this issue labels Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
3 participants