Repository navigation
A brief network drop no longer freezes the download - #7
Merged
Merged
Conversation
A request caught in a VPN reconnect could stay pending forever: fetch had no timeout and retries ran only when it rejected. Headers and body now share an idle timer (20 s of silence fails the attempt), a dropped network is retried for up to two minutes with the panel saying so, and a body cut off halfway is fetched again. The translator gets the same treatment. Closes #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ys down Review of the first version: the translator's grace window restarted on every chapter, so a long outage took chapters x 2 minutes with no word in the panel. Now one clock serves the whole download (and one per translator), a network error ends the translation and leaves the remaining chapters in the original, and the wait is announced while translating too. The idle timer restarts when headers arrive, the pace is widened once per outage, and the outage is timed with performance.now(). Tests cover a fetch that reports the timeout as an AbortError, a 503 retry, the shared clock, and cancelling a hung translation; timing margins hold under 8x parallel load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
A user reported that a VPN dropped for a few seconds during a download, and the progress stopped for good (#5).
Cause.
request()insrc/core.tsretried only whenfetchrejected. A request in flight when the connection silently died stayed pending forever: there was no timeout, so the retry loop never ran. The body was also read outside the loop. A drop mid-body could hang the same way or fail the whole book.Change.
src/lib/net.ts:fetchFullymakes one attempt, with headers and body under a single idle timer (20 s without a byte fails it). Every await is raced against that timer, so even a fetch that ignores its signal cannot hang the download. A cancel by the user is still a cancel, not a network error.src/core.ts: a dropped network is retried for a stretch of time (up to 2 min), not for a count of attempts. The clock is one per download (createOutage), so a long outage ends every request at once instead of each waiting its own window. Backoff is capped at 8 s, so a network that comes back is noticed quickly. The panel reads "The connection dropped — retrying in N s…". After that the download stops with the existing "The network is not responding" error, still markednetwork, so no generic re-parse runs. HTTP retries are unchanged: 5 attempts,Retry-After. The rate limiter is penalised once per outage, not on every retry, so the pace after a drop does not collapse to the maximum interval. The idle timer restarts when headers arrive.src/translate/google.ts/book.ts: the same for translation requests, with one clock per translator (one per book). The wait is announced through a new optionalnoticeargument ofTranslator.translate. If the network stays down past the window,translateBookstops and leaves the remaining chapters in the original, as it does for a refused chapter, instead of waiting out a new window per chapter.Checked.
test/net.ts(16 tests) andtest/translate.ts(+1) cover:AbortError, as browsers do: it is retried, not treated as a cancel;translateBookstopping after a network error;core.tswith a never-settling first request is still pending after 5 s with one attempt, which reproduces the report. The new one finishes on the second attempt.npm run checkpasses: typecheck, build and 26 + 20 + 36 + 16 tests.Kept as a trade-off: every fetch rejection counts as an outage. A VPN drop shows up as instant rejections while
navigator.onLinestays true, so failing fast on those would defeat the fix. Adapters fetch same-origin, so CORS or ad-blocker rejections are rare.Not done: chapters already fetched are not kept across a failed download. With a 2-minute grace this only matters for long outages, and keeping them is a bigger change.
Closes #5
🤖 Generated with Claude Code