Skip to content

[BUG] Leaked function closures in alarm invocation #827

@lukevalenta

Description

@lukevalenta

Is there an existing issue for this?

  • I have searched the existing issues

What version of workers-rs are you using?

0.6.6

What version of wrangler are you using?

4.38.0

Describe the bug

As mentioned in #722 (comment), there's a slow memory leak that can be triggered by spinning a Durable Object with a periodic alarm. I seem to be able to trigger it both with a 1s alarm (so that the DO does not hibernate) and a 15s alarm (so the DO hibernates in between alarm invocations).

Based on a memory profile taken with devtools (npx wrangler dev and then press d to bring up devtools), it looks like 1-2 kB of function closures are being leaked on each invocation.

In the image below, I ran garbage collection (broom icon) before each memory snapshot. Between snapshots 4 and 5, there was 23.7kB leaked in 154 leaked functions.
Image

I'm been able to observe increasing memory usage both locally with npx wrangler dev and in a deployed worker via internal Cloudflare metrics.

Steps To Reproduce

Code to reproduce is at https://github.com/lukevalenta/workers-rs/tree/f2899fe14a37cd6bce81edc6f08d4f1b7819fec1/do-alarm-memory-leak.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions