Skip to content

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

@mathewzile

Description

@mathewzile

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

Metadata

Metadata

Labels

status: accepting prsMocha can use your help with this one!type: buga defect, confirmed by a maintainer

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions