SebG
SebG10h ago

Memory leak when conditionally stubbing fetch

I'm having an issue during a test using @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.
No description
1 Reply
SebG
SebG7h ago
I am a fool... Missing await on db.execute in a middleware. C'est la vie :deno_it_works: