Skip to content

fix(download): six-hour sessions, purge waits for running downloads (#31, #32) - #64

Merged
Hiczownik merged 1 commit into
mainfrom
fix/download-sessions-and-purge
Oct 21, 2026
Merged

Hiczownik merged 1 commit into
mainfrom
fix/download-sessions-and-purge

Conversation

@Hiczownik

Copy link
Copy Markdown
Owner

Summary

A download session lasted a fixed 15 minutes, and the purge deleted a closed bundle's files a fixed 25 minutes after it closed. Anything slower broke:

Agreed design (discussed before building):

1. Sessions last 6 hours, never past the bundle's expiry

DownloadTimings.SessionLifetime: 15 min → 6 h. The existing cap at the bundle's ExpiresAt stays, so expiry remains hard. This covers a 5 GB bundle on a slow connection, and retrying after a dropped connection without counting another download. It's also the cap on re-downloading with one counted download. A fixed lifetime was chosen over a renewing one: the renewing version gave no extra protection (a holder could renew up to the cap anyway), needed keep-alive requests, and failed exactly when a connection dropped for more than 15 minutes.

2. The purge waits for running downloads

Before, it waited a fixed 25 minutes after the bundle closed. Now it skips a closed bundle while any of its sessions is still active, or ended less than StorageDeletionGracePeriod (= URL lifetime + 5 min) ago. That grace is also all it waits after closing, so storage isn't held longer than needed when nothing is downloading.

3. A clear message when the connection drops

"The connection was lost while downloading. Click Download again: trying again within the next few hours doesn't use up another of this bundle's downloads." This replaces a technical error. isConnectionLost recognises browsers' fetch/stream network errors (Chrome, Firefox, Safari wording) and API calls that got no response, but not tampering, programming errors or server answers.

Test plan

  • Purge keeps a bundle that closed 2 h ago while its session runs, and deletes it once the session plus grace has passed. Without the new check, the test fails (checked: the files were deleted mid-download).
  • A session lasts 6 h; on a bundle expiring in 1 h it ends at the bundle's expiry
  • Connection drops mid-download → the message is shown; the retry reuses the same session (openDownloadSession called once)
  • isConnectionLost for each browser's wording, and not for tampering, TypeErrors from bugs, server answers, or cancelled requests
  • dotnet test 55 unit + 135 integration; vitest 189; tsc -b, eslint clean

Fixes #31
Fixes #32

🤖 Generated with Claude Code

…clear message on a dropped connection

A download session lasted a fixed 15 minutes and the purge deleted a closed bundle's files a fixed
25 minutes after it closed, so anything slower broke: the encrypted Download All opened a new
session (counting another download, or failing on a 1-download bundle) for files after minute 15,
and a long server-built ZIP could have its files deleted mid-stream.

- A session now lasts 6 hours, never past the bundle's own expiry. That covers a 5 GB bundle on a
  slow connection, and retrying after a dropped connection without counting another download.
  It is also the cap on re-downloading with one counted download.
- The purge waits for a closed bundle's sessions to end (plus the lifetime of the last URL they
  could issue) instead of a fixed 25 minutes, so it never deletes files under a running download,
  and doesn't hold storage longer than needed otherwise.
- A download that fails because the connection dropped now says so, and that trying again soon
  doesn't use up another download, instead of a technical error.

Fixes #31
Fixes #32

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant