lquixada / cross-fetch

Universal WHATWG Fetch API for Node, Browsers and React Native.
MIT License
1.67k stars 104 forks source link

Possible memory leak #87

Closed artem-kurnikov closed 3 years ago

artem-kurnikov commented 3 years ago

Seems like cross-fetch has a memory leak. Tested in the browser (Google Chrome, 88). The issue is reproduced by simple script (ignore CORS error, it behaves the same when request is resolved) which fires requests in interval:

setInterval(() => {
  fetch('https://google.com')
    .then(console.log, console.log)
}, 250)

After profiling around 1 minute, we can see that event listeners are constantly growing:

image

While they are fine with native fetch:

image

lquixada commented 3 years ago

hey @tigger9flow ! thanks for reporting that. In the browser, cross-fetch is just a wrapper around whatwg-fetch. Can you check if that is happening there as well?

Here's some code to help:

<script>
  // Delete native fetch api to force the polyfill installation
  delete window.fetch
  delete window.Request
  delete window.Response
  delete window.Headers
</script>
<script src="https://unpkg.com/whatwg-fetch@3.5.0/dist/fetch.umd.js"></script>

If it does, please report the issue on https://github.com/github/fetch/issues. Otherwise, please let me know so I can take a look.

artem-kurnikov commented 3 years ago

Hey, @lquixada! You're totally right, it's reproduced in whatwg-fetch as well. Sorry for bothering you, I just haven't managed to find the dependency of browser-specific implementation of fetch. Duplicated the issue in whatwg-fetch repo. Thank you! :)

lquixada commented 3 years ago

no worries @tigger9flow ! happy to help! thanks for reporting the issue on whatwg-fetch!