deno: Memory leak in Deno (on Deno versions >= 1.31.0)

The below very simple program will ostensibly (at a rate of ~1MB/second) leak memory in Deno (only on Deno versions >= 1.31.0). To reproduce, please add a hello.txt file with a random content such as Hello! at the root and run the below program:

const file = new URL('./hello.txt', import.meta.url).pathname;
while (true) {
  Deno.readFileSync(file);
}

The memory leak only happens on Deno versions >= 1.31.0. It does not happen on Deno versions <= 1.30.3. The memory leak is more significant with shorter files.

Here is a slightly longer version of the program that will output the memory usage every second :

console.log('Deno version', Deno.version.deno);

const file = new URL('./hello.txt', import.meta.url).pathname;

let timestamp = new Date();

while (true) {
  if (Date.now() >= timestamp.valueOf()) {
    const bytes = Deno.memoryUsage().rss;
    console.log(timestamp.toISOString(), Math.floor(bytes / (1024 * 1024) * 10) / 10);
    timestamp = new Date(timestamp.valueOf() + 1000);
  }
  Deno.readFileSync(file);
}

I have also created a repository that showcases the issue: https://github.com/quentinadam/deno-memory-leak.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 1
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Bisected, and unfortunately it’s this:

65500f36e870b4ada3996b06aa287e30177d21a3 is the first bad commit
commit 65500f36e870b4ada3996b06aa287e30177d21a3
Author: Bartek Iwańczuk <biwanczuk@gmail.com>
Date:   Tue Feb 7 13:36:41 2023 +0100

    chore: upgrade rusty_v8 to 0.62.2 (#17604)
    
    Co-authored-by: Bert Belder <bertbelder@gmail.com>

 Cargo.lock                                         |   4 ++--
 Cargo.toml                                         |   2 +-
 .../run/worker_close_in_wasm_reactions.js.out      |   1 +
 core/icudtl.dat                                    | Bin 10454784 -> 10541264 bytes
 core/inspector.rs                                  |  18 ++++++++++++++++++
 core/ops_builtin_v8.rs                             |   8 ++++----
 core/runtime.rs                                    |   4 ++--
 7 files changed, 28 insertions(+), 9 deletions(-)

No, it’s not. I will be released later this week 👍

We’ll look into the V8 upgrade problem this week.

Hey @lucacasonato unfortunately I cannot share the code. I have restarted a process with 1.32.1 and will try to capture the crashdump. It can take several hours so I’ll report back when I have something.