-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Test case is leaking async ops when using clearTimeout inside finally block after not catching error #8954
Comments
We're already trying to mitigate this with a call to This was previously tracked here #4602 but can still be an issue. |
@caspervonb I think the actual issue is that the delay from that PR only happens if the awaited test function does not have an error. If there is an error, the await delay(0) is skipped along with the post metrics, then it continues to the next test getting the pre metrics without any delay between the clearTimeout and the pre metrics call. const pre = metrics();
await fn();
// Defer until next event loop turn - that way timeouts and intervals
// cleared can actually be removed from resource table, otherwise
// false positives may occur (https://github.com/denoland/deno/issues/4591)
await delay(0);
const post = metrics(); I think putting the delay in a finally would fix the issue. From my examples, a delay after the clearTimeout in the async4 test fixes the issue, preventing async5 from failing with a leaking async ops error. const pre = metrics();
try {
await fn();
} finally {
// Defer until next event loop turn - that way timeouts and intervals
// cleared can actually be removed from resource table, otherwise
// false positives may occur (https://github.com/denoland/deno/issues/4591)
await delay(0);
}
const post = metrics(); |
Right, easiest is often the best. |
If you use finally statements to do test cleanup, you can end up with the following test falsely reporting leaking async ops. In the below tests, you wouldn't expect
sync2
andasync2
to be leaking ops since they are not really doing anything but they end up failing with that error. I found that if you add a delay after you clearTimeout, the following testasync5
will not falsely report leaking async ops.The text was updated successfully, but these errors were encountered: