Skip to content

Multiplex torrent peer actors with bounded lifetime ownership - #205

Closed
linroid wants to merge 2 commits into
torrent-v2-08-peer-actorfrom
torrent-v2-08-peer-pool
Closed

linroid wants to merge 2 commits into
torrent-v2-08-peer-actorfrom
torrent-v2-08-peer-pool

Conversation

@linroid

@linroid linroid commented Sep 12, 2026 •

Copy link
Copy Markdown
Owner

A session needs one event stream for dynamically arriving and departing peer actors. PeerV2Pool now forwards each peer's ordered events through an admitted bounded queue, isolates connection failures, and supports nonblocking stop requests.

A terminal event is published only after the peer actor and reader have joined. The session retires that exact event before capacity returns, so delayed events cannot retire a replacement connection. Attach transfers cleanup responsibility even if actor admission fails or shutdown precedes startup. Queued and canceled-send events release their buffers; already delivered events remain consumer-owned.

Stacked on #204; part of #162. Automatic session scheduling, discovery, complete hash serving, and production runtime registration remain outstanding.

Validation at 597771a2bc1404117edee817dcd77cc53e636c34: 482 JVM and 461 executed iOS simulator tests, zero failures/errors/skips; both pinned v1 conformance scenarios and native dependency guard passed. New tests cover dynamic capacity and stale retirement, stop before startup, malformed-peer isolation with a healthy peer's ordered acknowledgement/payload, actor admission failure cleanup, and shutdown across both queue layers plus blocked forwarders.

Review follow-up cecc58a2: intentional stops use a dedicated cancellation marker and report a clean closure when no cleanup errors accompany it. The active-peer regression failed before the fix and passed after it. The dependent session branch at fe5d73c57da3654ee46544abd891ffc951e2d073 includes this fix and passed 489 JVM / 468 executed iOS tests, both pinned v1 conformance scenarios, and the native dependency guard.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-12T19:31:52.509931Z 597771a PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 597771a2bc

ℹ️ 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".

Comment on lines +85 to +87
peer.stop.onAwait {
owner.cancelAndJoin()
if (outcome.isCompleted) outcome.await() else null

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Treat requested stops as clean closures

When stop(peer) wins after the owner coroutine has started, cancelAndJoin() injects a CancellationException, which the owner's broad catch (Throwable) stores in outcome; the subsequent outcome.await() therefore publishes that exception as Closed.cause. Consequently, an intentional peer stop is indistinguishable from a connection failure (and differs from the stop-before-start path, which reports null), so session logic may incorrectly record or react to a routine retirement as an error.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Fixed in cecc58a. The pool uses a dedicated cancellation marker for an intentional stop and reports a clean closure only for that marker without suppressed cleanup errors. Genuine connection failures remain errors. Added an active-peer stop regression: it failed before the change and passes after it, alongside the existing startup, failure-isolation, admission, and ownership tests. JVM tests and iOS compilation passed; the dependent session branch is running full JVM/iOS validation with this fix.

@github-actions

github-actions Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Test Results

  687 files  + 5    687 suites  +5   4m 2s ⏱️ -1s
2 828 tests +15  2 828 ✅ +15  0 💤 ±0  0 ❌ ±0 
3 792 runs  +25  3 792 ✅ +25  0 💤 ±0  0 ❌ ±0 

Results for commit cecc58a. ± Comparison against base commit a19282e.

♻️ This comment has been updated with latest results.

@linroid

linroid commented Sep 20, 2026

Copy link
Copy Markdown
Owner Author

Superseded by #236 (V2 scheduling and download execution) in the consolidated eight-PR stack for #162.

The replacement preserves this PR's code and subsequent fixes; its description links the original head and review discussions. The only additional consolidation fix is the CI-discovered listener cancellation regression, documented on the replacement. All eight replacements have passed their required CI checks.

Closing without merging. This branch and its discussions remain available for reference. Review index: #162 (comment)

@linroid linroid closed this Sep 20, 2026
@linroid
linroid deleted the torrent-v2-08-peer-pool branch September 20, 2026 11:13
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.

1 participant