Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic Scope access causes a memory leak #3440

Closed
mikearnaldi opened this issue Aug 11, 2024 · 0 comments · Fixed by #3441 or #3519
Closed

Dynamic Scope access causes a memory leak #3440

mikearnaldi opened this issue Aug 11, 2024 · 0 comments · Fixed by #3441 or #3519
Labels
bug Something isn't working

Comments

@mikearnaldi
Copy link
Member

What version of Effect is running?

3.x

What steps can reproduce the bug?

The following code ends up creating a memory leak:

const program = Effect.scoped(Effect.gen(function*() {
  while (true) {
    yield* Effect.all([Effect.void, Effect.void], { concurrency: "unbounded" })
    yield* Effect.sleep("5 millis")
  }
}))

The reason is that all uses forEach and forEach dynamically accesses Scope in order to execute finalizers according to the strategy specified in concurrency. It all sounds like a nice feature but to do that we need to create a child scope that cannot close until the parent closes, and doing this repeatedly ends up adding an unbounded amount of finalizers into the parent Scope which may be created further up (and in theory may never close).

This bug was discovered by the JUCR folks and was also found in ZIO, the choice of action for ZIO has been to remove the feature altogether, I think we can do better and allow the feature with a specific flag since this only materialise when the forEach itself is repeated & when you have a parent Scope that never closes.

What is the expected behavior?

No response

What do you see instead?

No response

Additional information

No response

@mikearnaldi mikearnaldi added the bug Something isn't working label Aug 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants