question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Endless recursion on circular dependencies

See original GitHub issue

Hello,

I have an issue when using clear-module within a Mocha unit test: I get an endless recursion. However if I run it outside of a test I don’t.

I have successfully used clear-module in tests before. It looks to be related to:

  • upgrading to clear-module: “4.1.0” as the example below works with “3.1.0”
  • clearing sshpk as this has circular dependencies defined

This works fine:

// demo.js
require('sshpk');
const clearModule = require('clear-module');
console.log('before');
clearModule('sshpk');
console.log('after');

produces:

% node demo.js
before
after

However if I run using mocha, it hangs on the call to clearModule:

require('sshpk');
const clearModule = require('clear-module');
console.log('before');
clearModule('sshpk');
console.log('after');

describe('yyy', () => {

    it('xxx', function () {
    });
});

produces:

% ./node_modules/.bin/mocha test/services/demo.spec.js
before

When I debug this I can see an endless recursion of clearing the sshpk modules which have a circular reference.

I am using node 12.6.0 and the following lib versions:

  • “mocha”: “7.1.0”
  • “clear-module”: “4.1.0” (previously 3.1.0 which worked)
  • “sshpk”: “1.16.1”

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
vectroniccommented, Mar 11, 2020

Confirmed fixed for me - thanks!

1reaction
omrilotancommented, Mar 4, 2020

I have reproduced the issue with the following steps:

  • create a new npm project and install mocha, sshpk, clear-module

  • Create a test file

const sshpk = require('sshpk');
const clear = require('clear-module');

describe('reproduce this issue', () => {
	it('Should not get stuck between Before and After', () => {
		console.log('Before');
		clear('sshpk');
		console.log('After');
	})
});
  • Run tests, get stuck after ‘Before’.
  • Link the solution in #14
  • Run the tests with desired result

#14 should definitely resolve this issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

Circular Dependencies - Endless Recursion #269 - GitHub
My idea is to move the value generation from generate_value(name, params) into their adequate Generator (e.g. Fabrication::Generator:: ...
Read more >
Value-equals and circular references: how to resolve infinite ...
Like you said, a infinite recursion can happen in circle of X length (example: after the 10 iteration it's pointing to the 2nd...
Read more >
Breaking Circular Dependencies in Recursive Union Types ...
A value itself is either a string, a number, true, false, null, or again an array or an object. Note the recursive structure...
Read more >
Circular dependencies - The Apache Software Foundation!
In software, a circular dependency is a relation between two or more classes ... a circular dependency can generate an infinite recursion leading...
Read more >
Catching circular references in parent-child structures
Now, if we say that “E” is the parent of “3”, we've created a circular reference, and we end up with an infinite...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found