Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@adamgfraser
Copy link
Contributor

Resolves #4135.

The issue is that if fiber A awaits Fiber B, A would add itself as an observer to B with a callback to be invoked when B completes. However, if A is then subsequently interrupted that callback would never be removed from B's list of observers. This could result in a memory leak in situations where effects were waiting on a fiber and then being interrupted many times. We address by adding logic so that when fiber A awaits fiber B, interruption logic is also added so that if A is interrupted the callback is also removed from B's observer list.

@adamgfraser adamgfraser requested a review from jdegoes September 1, 2020 22:30
Copy link
Member

@jdegoes jdegoes left a comment

Choose a reason for hiding this comment

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

Looks good, can we get that test added?

@adamgfraser
Copy link
Contributor Author

@jdegoes I added the test to #4121 for preventing interruption when closing scopes. Not sure how to test this one since I don't think we expose the list of observers of a fiber anywhere outside of FiberContext. I added a debug statement with the number of observers to verify that it was no longer growing in the original example. We could include observers as a method on runtime fibers but not sure if that is exposing too much of an implementation detail.

@jdegoes
Copy link
Member

jdegoes commented Sep 2, 2020

Ok, sounds good!

@jdegoes jdegoes merged commit 641ad34 into zio:master Sep 2, 2020
@adamgfraser adamgfraser deleted the 4135 branch September 2, 2020 00:54
@ollyw
Copy link
Contributor

ollyw commented Sep 2, 2020

Thanks for the fix and following up so fast @adamgfraser.

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.

Memory leak when racing join

3 participants