temporalio / temporalio/sdk-ruby
[Feature Request] Ensure fibers and workflow instances are properly GC'd on workflow eviction
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 204
- Forks
- 42
- Avg merge
- 1d 30m
- Merged PRs (30d)
- 28
Description
Describe the solution you'd like
It was originally thought that if nothing in user code was referencing a suspended fiber anymore, it would get garbage collected (this is how tasks work in .NET). However, threads actually keep a strong reference to suspended fibers and we reuse threads. On workflow eviction, any number of fibers may be suspended, including the primary one.
The only way to remove a strong reference to a fiber on a thread is to complete the fiber, and the only way to complete the fiber is resume until complete (potentially raising an exception inside it to force it to resume). So we should go over known fibers and raise a non-standard-error exception inside them. This needs to take an approach similar to https://github.com/temporalio/sdk-python/pull/499 where we ignore any side-effects that could be caused by raising (e.g. don't make an activity command if the user did it inside ensure). Make sure there is a test that tries to make uncollected fibers in any way it can and confirm. The test_confirm_garbage_collect test (that we had to skip pending this issue) has some utilities/designs here.
EDIT: These statements about threads holding strong references to fibers are no longer deemed accurate, see first comment.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the first comment and the skipped test_confirm_garbage_collect test, including its existing utilities and designs. Establish whether workflow eviction can leave fibers or workflow instances uncollected, then define a testable eviction scenario whose completion confirms they are garbage collected without unintended side effects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend, distributed-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100