Run v2 downloads under shared engine ownership and admission - #228
Run v2 downloads under shared engine ownership and admission#228linroid wants to merge 2 commits into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ab29c5c426
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| discover: suspend (SendChannel<PeerEndpoint>) -> Unit, | ||
| body: suspend (TorrentV2DownloadSession) -> T, | ||
| ): T { | ||
| val pending = scope.async { |
There was a problem hiding this comment.
Prevent shutdown from joining its own v2 child
When the supplied body or discover callback calls engine.stop(), it is executing inside this engine-scope child. stop() cancels scope and then joins the scope's root job, which cannot complete until this same child returns, while the child cannot return until stop() does; the call therefore deadlocks. Run caller callbacks outside the owned child or make shutdown avoid joining the calling child.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 8b6b1c1. Shutdown now has a single cleanup operation outside the engine job tree. An engine-owned callback requests that operation without joining its own ancestor; external stop calls await the same full cleanup barrier. Regressions call stop from both the v2 body and discovery callback, then await external stop and assert that admission returned. The combined local capability branch passes 618 JVM tests, 597 executed iOS simulator tests, the runtime guard, and both existing v1 conformance scenarios.
The Kotlin engine can now own a scoped full-metainfo v2 download using its shared connection, transfer-memory, session-memory, and payload-file limits. Caller cancellation and engine shutdown join the v2 lifetime before releasing its metadata admission and output claim. Files remain intact when ownership ends.
V1 and v2 registrations share the active-task ceiling and output-overlap checks. Full v2 identities prevent duplicate registrations, hybrid v1 aliases cannot acquire independent legacy owners, and legacy removal cannot release a live v2 output claim. File/piece/info bounds and retained metadata/index admission run before storage construction.
Stacked on #227 for #162. Real TCP coverage downloads a pure v2 file and a selected hybrid file after padding. Other tests cover shared registration limits, duplicate identities/output paths, pre-I/O admission failures, and joined engine shutdown. Both TCP peers are Ketch fixtures.
Validation: full JVM and executed iOS simulator suites, native-runtime dependency guard, and both existing Transmission v1 conformance scenarios. Public v2 source resolution, incoming routing, integrated discovery, checkpoint/TaskStore recovery, rate controls, and seeding remain roadmap work; this internal scoped path is not advertised as public v2 capability.