fix(runtime): split the runtime to avoid ref cycle#911
Open
Berrysoft wants to merge 2 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors compio-runtime to break a runtime/task reference cycle by splitting Runtime into separately reference-counted components and updating cancellation/submission/timer futures to hold driver/timer handles rather than a full Runtime clone. It also adds a regression test asserting that detached tasks are dropped when the runtime is dropped, even if they hold a CancelToken.
Changes:
- Refactor
Runtimeto holdRc<Executor>andRc<RefCell<Proactor>>(and timer runtime) directly, with newcurrent_driver()/current_timer_runtime()helpers. - Update
CancelToken,Submit,SubmitMulti, and timer futures to use the shared driver/timer runtime handles and move driver polling helpers intofuture/mod.rs. - Add a new drop regression test to detect potential Rc cycles keeping tasks alive across runtime drop.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| compio-runtime/tests/drop.rs | Adds a regression test ensuring a detached task holding a CancelToken is dropped when the runtime drops. |
| compio-runtime/src/time.rs | Moves timer creation logic into time.rs and makes timer futures own an Rc<RefCell<TimerRuntime>>; adds TimerRuntime::poll_timer. |
| compio-runtime/src/lib.rs | Splits Runtime into separate Rc fields, adjusts submit APIs to pass driver handles, and changes drop logic to key off executor refcount. |
| compio-runtime/src/future/stream.rs | Changes SubmitMulti to store the driver handle and use shared poll/submit helpers. |
| compio-runtime/src/future/mod.rs | Introduces shared internal helper functions for submit/poll operations against Proactor. |
| compio-runtime/src/future/future.rs | Changes Submit to store the driver handle and use shared poll/submit helpers. |
| compio-runtime/src/cancel.rs | Changes CancelToken internals to store the driver handle (instead of Runtime) and adjusts debug output accordingly. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
453ed63 to
db14930
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #909
I think this solution is better. Let's see the ASan results.
cc: @paddor