Skip to content

Memory leak when converting a Promise from an Unknown #2926

@hecsalazarf

Description

@hecsalazarf

A memory leak occurs when converting a promise from an Unknown object using Promise::from_unknown. According to the memory profiler, the leak appears to be associated to the invocation of napi_call_function in Deno.

The following example reproduces the issue.

#[napi]
pub fn leak_from_promise<'e>(unknown: Unknown<'e>) -> Result<()> {
  if unknown.is_promise()? {
    Promise::<Undefined>::from_unknown(unknown)?;
  }
  Ok(())
}

Repeatedly calling leakFromPromise() results in a gradual increase of RSS memory.

setInterval(() => {
  leakFromPromise(Promise.resolve())
}, 10)

Interestingly, this behavior does not occur in Node.js.

Deno version: 2.5.0
napi-rs version: 3.3.0

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions