Skip to content

Conversation

durban
Copy link
Contributor

@durban durban commented Oct 8, 2025

Should fix issue #4490.

Reproducing that issue with the repro in the description there:

[info] Memory taken: 6 MB
[info] Memory taken: 520 MB

With this PR:

[info] Memory taken: 6 MB
[info] Memory taken: 7 MB

This issue also adds an (ugly) unittest, which inspects the internal state of the Supervisor. We could remove that, if we're satisfied with the fix, but I think it's useful to have it.

(Draft, because the test is racy, so I'm waiting for any possible CI failures.)

@durban durban linked an issue Oct 8, 2025 that may be closed by this pull request
apply[F](false)

private sealed abstract class State[F[_]] {
private[std] sealed abstract class State[F[_]] {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the changes in Supervisor are just to make it testable (its internal state inspectable).


case None => (fa, fin) => F.start(fa.guarantee(fin))
case None => { (fa, fin) =>
F.start(fa).flatMap { fib => F.start(fib.join.guarantee(fin)).as(fib) }
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the actual fix.

(I believe the other case is already correct, because cancel joins the underlying fiber.)

@durban durban marked this pull request as ready for review October 8, 2025 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supervisor leaks memory when fibers are canceled quickly

1 participant