DenoDDeno
Powered by
SebGS
Denoβ€’2y agoβ€’
1 reply
SebG

Memory leak when conditionally stubbing fetch

I'm having an issue during a test using
@std/testing/mock
@std/testing/mock
where I want to stub fetch for only a specific URL (an OAuth token exchange endpoint) receiving a mocked response in this case. For all other fetches, I want the fetch to behave normally. Everything seems to be functional however the test is failing due to fetchCancelHandles not being cleared up but I really can't see how this could happen as all requests made have their bodies consumed.

I wondered if any smarter people have experienced this before or have any answers as to why this specific behaviour is arising.

Error:
Leaks detected:
  - "fetchCancelHandle" was created during the test, but not cleaned up during the test. Close the resource before the end of the test.
  - An async call to op_http_wait was started before the test, but completed during the test. Async operations should not complete in a test if they were not started in that test.
  - An async call to op_http_wait was started in this test, but never completed.
  - An async operation to send a HTTP request was started in this test, but never completed. This is often caused by not awaiting the result of a `fetch` call.
To get more details where leaks occurred, run again with the --trace-leaks flag.
Leaks detected:
  - "fetchCancelHandle" was created during the test, but not cleaned up during the test. Close the resource before the end of the test.
  - An async call to op_http_wait was started before the test, but completed during the test. Async operations should not complete in a test if they were not started in that test.
  - An async call to op_http_wait was started in this test, but never completed.
  - An async operation to send a HTTP request was started in this test, but never completed. This is often caused by not awaiting the result of a `fetch` call.
To get more details where leaks occurred, run again with the --trace-leaks flag.
carbon.png
Deno banner
DenoJoin
Chat about Deno, a modern runtime for JavaScript and TypeScript.
20,934Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Memory leak
buttercubzBbuttercubz / help
2y ago
Memory leak in Deno.serve?
pakastinPpakastin / help
17mo ago
Stubbing @std/x
thorocTthoroc / help
13mo ago
Deno memory leak when running typescript language server in ElysiaJS
BanDroidBBanDroid / help
3mo ago