Skip to content

fix: fix memory leak when using nock with jest - #2572

Merged
gr2m merged 1 commit into
nock:mainfrom
VladimirChuprazov:fix-memory-leak-in-jest
Jan 28, 2024
Merged

gr2m merged 1 commit into
nock:mainfrom
VladimirChuprazov:fix-memory-leak-in-jest

Conversation

@VladimirChuprazov

Copy link
Copy Markdown
Contributor

Just importing nock in a Jest test is enough to have a memory leak.
Fix for #2358

@gr2m

gr2m commented Jan 28, 2024

Copy link
Copy Markdown
Member

Thank you for taking on this problem! Unfortunately your change seems to have broken the Node 10 and 12 tests (I know).

Maybe only run test:jest in CI when Node version is at least 14? We will bump to Node 20 as part of fixing #2397

@VladimirChuprazov

Copy link
Copy Markdown
Contributor Author

Hey @gr2m, just updated the job

@VladimirChuprazov

VladimirChuprazov commented Jan 28, 2024 •

Copy link
Copy Markdown
Contributor Author

Looks like need to fix the command for windows as well 😄

@VladimirChuprazov

Copy link
Copy Markdown
Contributor Author

@gr2m should be ok now, checked in my repo

@gr2m gr2m left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@gr2m
gr2m merged commit 7468cf1 into nock:main Jan 28, 2024
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 13.5.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@perrin4869

Copy link
Copy Markdown

hm... the removal of

    const module = {
      http: require('http'),
      https: require('https'),
    }[moduleName]

broke my tests. Patching it back in fixed it. I didn't look into the root causes but obviously http and https need to be preloaded...

@VladimirChuprazov

Copy link
Copy Markdown
Contributor Author

@perrin4869 could you create a minimal reproduction repository?

@perrin4869

perrin4869 commented Jan 31, 2024 •

Copy link
Copy Markdown

well of course I'd like to setup a minimal reproduction and write a regression test to make sure it doesn't break again in the future ^^;;
I expect it wouldn't be easy to get a minimal reproduction, since the code that broke actually runs inside a lambda so I cannot easily reproduce it locally, I may try today or this week

@gr2m

gr2m commented Feb 1, 2024

Copy link
Copy Markdown
Member

it's most likely weird lambda code bundling ... I've been bitten by this before. I'd suggest we revert this particular change and add a comment with a warning for future contributors to ... just leave it alone 😁

@perrin4869

Copy link
Copy Markdown

@gr2m that's be super helpful! I'm sure it was coded that way for a reason 😅

@markmssd

Copy link
Copy Markdown

Thanks for the fix @VladimirChuprazov !

I'm curious whether https://www.npmjs.com/package/nock#memory-issues-with-jest is still relevant with this fix now, would you know?

@Uzlopak

Uzlopak commented Feb 25, 2024

Copy link
Copy Markdown
Member

@markmssd
How about you satisfy your curiosity and check if that is still relevant and report it back? ;)

@markmssd

Copy link
Copy Markdown

Still required :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants