-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
Description
There are quite some memory leaks in Cloudflare. One of the biggest one is that the CloudflareClient can't be garbage collected and stays in memory forever, this is actually working as expected, as usually we only have one client and it is usually never removed.
In Cloudflare Workers we actually don't know how long isolates live. So when a lot of requests come in rather fast the request is actually done, but the client is still active, which takes some memory - this could lead to OOM of the worker, as it is limited currently to 128MB per worker.
Possible solution
We don't know how long an isolate will live, but we do now how long a request takes (as we can hook into all waitUntil). As an isolate can't be reused it is guaranteed that a new request will spawn a new isolate and therefore a new client. With that it is safe to assume that we can mark an client as "disposed" so it can be garbage collected.
Repro
https://github.com/JPeer264/temp-cloudflare-leak
There is a reproduction showing the memory leak over time. There is also an experimental fix applied, which disposes clients.
Metadata
Metadata
Assignees
Labels
Projects
Status