Deno: Test Case Is Leaking Resources.

E Ozcelik
E Ozcelik
Sep 12, 2020 · 2 min read

SUMMARY OF THE PROBLEM

Recently, I have been working on an open-source Deno project centered around automatically generating documentation for your code based on your tests.

During the testing process, particularly, when Deno interacts with external resources, I was getting a strange error that looked like this :

SOLUTION

This is caused by Deno’s internal architecture which holds a record of open files, sockets and other concepts.

You can close a single resource by its RID :

Some functions provide easy access to this RID id. For example:

Then, some other functions expose methods to close the resource internally :

However, some functions are not that easy to handle. For example, Deno.createSync() does not return a handle for the opened resource. For these kind of situations, at any moment in a Deno program, you can get a list of open resources to target specific resources or iterate over all open resources.

If you are looking for a quick solution for your tests without messing with RID ids, you can simply ignore this mechanism by restructuring your tests as follows:

REFERENCES

Being a new technology, it was somewhat hard to get a clear answer. As always, a Stackoverflow question was one of the few pertinent elements:

Then, of course, there is the official documentation which provides more clarification.

Unfortunate that the documentation doesn’t appear among the top results during a Google search. Also, this problem is discussed only within the context of testing but I would assume this is as much relevant for your run-of-the-mill Deno project to prevent memory leaks. If you think otherwise, don’t hesitate share with me.

Get smarter at building your thing. Join The Startup’s +800K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store