Repository navigation
fix(torrent): keep seeding counters across restarts and report discarded payload - #574
Conversation
…ded payload Seeding sessions never saved their checkpoint into the task record, so a seeding task's uploaded payload went back to its value at completion after a restart. They now save it through the new SourceHost.saveSourceState about every minute, as they stop and as the source closes, and snapshots without a session report the saved counters. Payload thrown away rather than verified (duplicate, late or stale blocks, corrupt pieces, abandoned partial pieces, failed web seed runs) is now counted in v1, v2 and web seeds, saved in both checkpoint formats and reported as TorrentCounters.discardedPayloadBytes.
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. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. 🤖 Generated with Claude Code |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4c32522c4b
ℹ️ 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".
…imits as discarded
…etch into fix/torrent-payload-counters # Conflicts: # docs/torrent.md # library/torrent/src/commonMain/kotlin/com/linroid/ketch/torrent/v1/TorrentSwarm.kt # library/torrent/src/commonMain/kotlin/com/linroid/ketch/torrent/webseed/TorrentV2WebSeeds.kt # library/torrent/src/commonMain/kotlin/com/linroid/ketch/torrent/webseed/TorrentWebSeed.kt
…etch into fix/torrent-payload-counters # Conflicts: # library/torrent/src/commonMain/kotlin/com/linroid/ketch/torrent/TorrentDownloadSource.kt
…t waits for lonelyStall_stillForgetsAPeerItGaveUpOn assumed the peer was given up at 60 s and found it again at a fixed 400 s. On a loaded machine (the macOS and iOS CI runners) the swarm handles each refused dial a step or more late, so the give-up came late and the peer was still remembered at 400 s: dialed once or twice instead of four times. The test now waits for the fourth dial, finds the peer again 340 s after it, and counts the dials of the next 90 s, letting the last step's dial land first. Under full CPU load it failed 2 to 3 runs in 10 before and none after.
Summary
Fixes two counter bugs that field tests of #570 found when restarting
ketch serveragainst real swarms. Based onfix/torrent-field-test(#570), so this diff holds only these changes.Seeding tasks lost their upload counts on restart
A checkpoint reached the task record only through
store()while a download ran. Two kinds of seeding session never wrote theirs back:TorrentControlsrestored throughstartSeeding.So after a restart, a seeding task's uploaded payload went back to its value at completion, often 0.
SourceHost.saveSourceState(task, state)(core) saves a completed task's source state for a session that runs outside a download. It never takes the task's control lock: a Stop command stops seeding fromafterSave, which already holds that lock.TorrentDownloadSource.stop(), whichKetch.close()andshutdown()await since fix(core): stop downloads and sources before closing the HTTP engine #573, lets them save, within 5 s, before it stops the engine.countersOfreads them from the record's checkpoint throughcheckpointPayload, which reads only the counters, not the metainfo.Discarded payload was counted as received and never reported
TorrentCounters.discardedPayloadBytesis now reported. It is the part of the received payload thrown away instead of verified:Both checkpoint formats save the count as
discarded. Older builds ignore the key, and older checkpoints read as 0.Test plan
./gradlew :library:core:jvmTest :library:torrent:jvmTeststop()before the engine stops;saveSourceStateguards, and a Stop command that saves without deadlocking. That test hangs with the lock taken.compileTestKotlinIosSimulatorArm64for core and torrent