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.)

Copy link
Member

@djspiewak djspiewak left a comment

Choose a reason for hiding this comment

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

Wow

It's really unfortunate how racy this is but the fix does look good to me. Excellent job.

@djspiewak djspiewak merged commit 9753bd7 into series/3.6.x Dec 28, 2025
155 of 169 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Supervisor leaks memory when fibers are canceled quickly

3 participants