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: Parallel mode crashes if test exception contains circular references #4552

Closed
4 tasks done
medikoo opened this issue Jan 13, 2021 · 4 comments · Fixed by synapsecns/synapse-contracts#95 or #5032
Closed
4 tasks done
Labels
area: parallel mode Regarding parallel mode status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer

Comments

@medikoo
Copy link

medikoo commented Jan 13, 2021

Prerequisites

  • Checked that your issue hasn't already been filed by cross-referencing issues with the faq label
  • Checked next-gen ES issues and syntax problems by using the same environment and/or transpiler configuration without Mocha to ensure it isn't just a feature that actually isn't supported in the environment in question or a bug in your code.
  • '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, your usage of Mocha, or Mocha itself
  • Ensured that there is no discrepancy between the locally and globally installed versions of Mocha. You can find them with: node node_modules/.bin/mocha --version(Local) and mocha --version(Global). We recommend that you not install Mocha globally.

Description

Parallel mode crashes or hangs if test exception contains circular references

Steps to Reproduce

1. Hangs if error has self reference:

Test file test.js

describe('Test', () => {
  it('test', () => {
    const error = new Error('Foo');
    error.self = error;
    throw error;
  });
});

Running following will simply hang:

$ mocha --parallel test.js

2. Crashes if error has circular references passed within array properties

Test file test.js

describe('Test', () => {
  it('test', () => {
    const error = new Error('Foo');
    error.foo = { props: [] };
    error.foo.props.push(error.foo);
    throw error;
  });
});

Running following

$ mocha --parallel test.js

will result with an error as:

 1) Uncaught error outside test suite

  0 passing (308ms)
  1 failing

  1) Uncaught error outside test suite:
     Uncaught TypeError: Converting circular structure to JSON
    --> starting at object with constructor 'Object'
    |     property 'props' -> object with constructor 'Array'
    --- index 0 closes the circle
      at stringify (<anonymous>)
      at writeChannelMessage (node:internal/child_process/serialization:120:20)
      at process.target._send (node:internal/child_process:819:17)
      at process.target.send (node:internal/child_process:719:19)
      at processTicksAndRejections (node:internal/process/task_queues:93:5)

Expected behavior:

Originally thrown exception should surface in report

Versions

  • The output of mocha --version and node node_modules/.bin/mocha --version: 8.2.1
  • The output of node --version: 15.5.1
  • Your operating system
    • name and version: macOS 10.15.7
    • architecture (32 or 64-bit): 64-bit
  • Your shell (e.g., bash, zsh, PowerShell, cmd): zsh
@outsideris outsideris added type: bug a defect, confirmed by a maintainer area: parallel mode Regarding parallel mode and removed unconfirmed-bug labels Jan 19, 2021
sam-super added a commit to sam-super/mocha that referenced this issue Nov 21, 2023
Breaks circular references in before objects are serialized to prevent
cryptic error in parallel mode.
@sam-super
Copy link
Contributor

This PR hopefully help with the second case (which is something we were seeing when developing with nestjs):
#5032

@JoshuaKGoldberg JoshuaKGoldberg changed the title Parallel mode crashes if test exception contains circular references 🐛 Bug: Parallel mode crashes if test exception contains circular references Dec 28, 2023
@JoshuaKGoldberg
Copy link
Member

Heh, on my machine now it just ... hangs indefinitely. Fun.

@voxpelli
Copy link
Member

Similar yet not similar to #4910

@JoshuaKGoldberg
Copy link
Member

Published in mocha@10.5.2. 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: parallel mode Regarding parallel mode status: accepting prs Mocha can use your help with this one! type: bug a defect, confirmed by a maintainer
Projects
None yet
5 participants