-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
Proxyquire is leaking on module.parent #174
Comments
Interesting. Never ran into this due to using/testing smaller modules, but I understand this can be annoying. Do I understand correctly that simply removing it from the If merged we should probably release a new major version (just to be sure as some people may depend on the current behavior). |
That could work. I'd have to check. |
How would it be leaking? what's holding onto it? |
That does not seem to be enough. Here's what my memory looks like after successive tests without a
And here's what it looks like with
|
When doing So, in proxyquire, here, here, and here. The module being loaded gets leaked onto
I'm guessing the closure that proxyquire is running in and, if not removed from the parent module, the module that required proxyquire. A spec file for instance. |
The only thing I can imagine is that one of your modules is kept in the require cache and keeps collecting proxyquire children somehow? |
I'm only requiring it once per file. |
OK you'd need to dig through the snapshot (retainers view) to find the actual source of your problem. Quite honestly though I see a possibility that the problem lies elsewhere in your code ... hard to tell as I don't have access to it or the snapshot and neither the bandwidth to dig into it. Keep posting any findings here and we'll try to help, but at this point there isn't much we can do. |
I would find it unlikely that the problem lies in our code since we hotswapped this project by https://github.com/charlespwd/proxyquire/ (not a fork) and we don't experience any leaks. I can comment both this line and this line and experience a memory leak. I can comment this block and also experience a memory leak. I even have unit tests that break if I comment the above lines covering the leak. All this without touching a single line of our application code. |
Not trying to argue about where leak is coming from, just mentioned that this is the first kind of this issue and wanted to open your eyes to the possibility. Obviously commenting parts of proxyquire could introduce mem leaks. As I said if you find a way to do that we'll gladly accept a PR. |
@charlespwd Did you ever find the root of the issue? We have the same problem and I can reproduce it with a single spec file. Every file save when using |
@rochdev, we ended up using my rewrite for our project. You could either use that or write your own. It wasn't too bad to do. It turns out to about 140 LOC. Great resources: |
@charlespwd Any plans to release it on npm? |
Sounds like this is not a problem for proxyquire, but for any other "nodejs" mocking library, as long they all work relatively the same. |
This comment has been minimized.
This comment has been minimized.
This problem was solved multiple times in multiple ways, and not solved in the same time. There are few things you can do:
Well, why not to open a PR in this case? - #261 |
This one took me a while to figure out, had to write my own "slim" proxyquire to find it.
Where I work, we use proxyquire to mock our modules and our test suite has around 1050 tests. We ran into issues where
mocha --watch
would crash after a couple of runs because the garbage collector was not able to garbage collect anymore.If I compare successive heap dumps I notice that as time goes by I end up having more and more Module objects.
If you look at the contructor of Module, you'll notice that whenever we load a new module, this one gets pushed as a children of the module's parent.
In my slim proxyquire, the fix for the leak was to simply
parent.children.pop()
whenever I callModule._load
and to also remove proxyquire from proxyquire's parent module.children.The text was updated successfully, but these errors were encountered: