fix(seedingtime): clamp elapsed duration to zero on clock skew - #3271
Merged
Conversation
When clock skew or measurement latency causes the browser's estimated server time to lag slightly behind rTorrent's completion timestamp (epochSeconds captured via date +%s), the elapsed duration calculates to a small negative number. Because theConverter.time does not clamp negative values, ruTorrent formats this directly as minus seconds (e.g. "-15s") in the Finished column. Clamp the duration to a minimum of zero in both the seedingtime request handler and theConverter.time so negative durations are never displayed.
There was a problem hiding this comment.
🟢 Approval recommended
No unresolved review comments remain, and all reviewed changes have approval readiness.
Pull request overview
Fixes negative elapsed-time displays caused by clock skew by clamping durations to zero and adding regression tests.
Changes:
- Clamp seeding and formatted durations to zero.
- Add tests for clock-skew and negative-duration handling.
File summaries
| File | Description |
|---|---|
tests/plugins/seedingtime/init.spec.js |
Tests clock-skew clamping. |
tests/js/common.spec.js |
Tests negative-duration formatting. |
plugins/seedingtime/init.js |
Prevents negative seeding durations. |
js/common.js |
Prevents negative duration display. |
Review details
- Files reviewed: 4/4 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Problem
When clock skew, client-server latency, or coarse 1-second HTTP Date header resolution causes the browser's estimated current time (
(new Date().getTime() - theWebUI.deltaTime) / 1000) to lag slightly behind the completion timestamp captured on the server (d.custom=seedingtimeviadate +%s), the elapsed duration evaluates to a small negative number.Because neither
plugins/seedingtime/init.jsnortheConverter.timechecked for negative values, ruTorrent formatted this directly as minus seconds (e.g.-15s) in the "Finished" column until the browser clock passed the finish timestamp.Solution
plugins/seedingtime/init.js, clamptorrent.seedingtimeto a minimum of0withMath.max(0, ...).js/common.js, clamp duration values intheConverter.timewithMath.max(0, tm)so negative durations are never displayed.tests/plugins/seedingtime/init.spec.jsandtests/js/common.spec.jscovering clock skew and negative duration clamping.Testing
npm testintests/): all 24 test suites and 290 tests pass.