Skip to content

Recover TUS uploads whose resume URL is no longer valid - #1145

Merged
TheOneRing merged 1 commit into
opencloud-eu:mainfrom
Mortimer-RR:fix/tus-stale-resume
Oct 12, 2026
Merged

TheOneRing merged 1 commit into
opencloud-eu:mainfrom
Mortimer-RR:fix/tus-stale-resume

Conversation

@Mortimer-RR

Copy link
Copy Markdown
Contributor

Fixes #1144 . Completes #898 together with #971: #971 recovers from a 409 on a PATCH; this
handles the resume HEAD failing because the upload is gone, which #971 skips.

Changes

src/libsync/propagateuploadtus.cpp PropagateUploadFileTUS::slotChunkFinished
(+ a member in propagateuploadtus.h):

  • If a HEAD to the upload URL fails with 404 or 410 (the server discarded or expired
    the upload) or 403 (the transfer token embedded in the URL expired), clear the saved
    resume info, reset _location and _currentOffset, and start a new creation-with-upload
    in the same run. At most once per propagation job (_restartedUpload), so a genuine 403
    can't loop: the new upload's own error is reported normally.
  • On 460 Checksum Mismatch (the server discarded the upload, opencloud-eu/reva#<4>),
    clear the saved resume info before the normal error handling, so the next attempt starts
    a new upload instead of resuming a dead URL.

classifyError is unchanged: 460 falls through to NormalError (retried).

Tests

test/testtusresume.cpp (added by #971) gets a small fake tus server on top of the fake remote
(creation-with-upload POST, PATCH, HEAD):

  • testResumeFromServerOffset: an interrupted upload still resumes from the server offset
    (HEAD, PATCH, PATCH); passes before and after.
  • testStaleResumeInfoRestartsUpload (data rows 404, 410, 403): the server lost the upload;
    the file uploads in the same sync (HEAD, POST, PATCH, PATCH) and the resume info is gone.
    Fails on main: the sync fails.
  • testChecksumMismatchClearsResumeInfo: 460 on the last PATCH clears the resume info; the
    next sync starts with POST. Fails on main: the resume info is kept.

All 35 tests pass (Linux, Qt 6.11.2). git clang-format clean.

End to end against a server with the reva fixes: a deliberately corrupted upload was
rejected with 460 and uploaded successfully on the next sync, and the client recovered from a
forced 5-minute chunk timeout and two dropped PATCH connections.

🤖 Generated with Claude Code

@TheOneRing TheOneRing linked an issue Oct 7, 2026 that may be closed by this pull request
@TheOneRing
TheOneRing force-pushed the fix/tus-stale-resume branch from 8799d56 to 7b67677 Compare October 8, 2026 14:07

@TheOneRing TheOneRing left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Comment thread test/testtusresume.cpp Fixed
Comment thread test/testtusresume.cpp Fixed
@Mortimer-RR
Mortimer-RR force-pushed the fix/tus-stale-resume branch from 7b67677 to 1df8afc Compare October 9, 2026 04:05
@Mortimer-RR

Copy link
Copy Markdown
Contributor Author

Addressed the two notes from the @github-advanced-security bot, and reworded the commit to follow the AI guideline (Co-Authored-By replaced with an Assisted-by tag).

@TheOneRing This PR adds a new FakeTusServer for the tests. The shared fake server in test/testutils/syncenginetestutils.cpp doesn’t support TUS yet. I have a local version that adds TUS support in syncenginetestutils.cpp (opt-in via FakeFolder::enableTus(), so existing tests are unaffected) and shrinks this test to a small request recorder.

Would you like me to include that in this PR, create a new PR that includes it, or should I keep the test as is.

@TheOneRing

Copy link
Copy Markdown
Contributor

I think the change is fine as is. thx.

The saved resume info of a TUS upload was only cleared after a
successful upload. When the server discarded an upload (for example
after rejecting it with 460 Checksum Mismatch, or when it expired), the
next sync sent HEAD to the old upload URL, got 404, and failed without
clearing the resume info. The file then never synced until it was
modified locally. The same happened when the transfer token embedded in
the URL had expired and the data gateway answered 403.

- If the resume HEAD fails with 404, 410 or 403, clear the resume info
  and start a new upload from offset 0 in the same run (once per job).
- Clear the resume info when the server answers 460 Checksum Mismatch,
  so the next attempt starts a new upload.

Tests use a small fake tus server in testtusresume.

Assisted-by: Claude:claude-opus-5-5
@TheOneRing
TheOneRing force-pushed the fix/tus-stale-resume branch from 1df8afc to fd2309d Compare October 12, 2026 11:47
@TheOneRing
TheOneRing enabled auto-merge (rebase) October 12, 2026 11:48
@TheOneRing
TheOneRing merged commit 26e753e into opencloud-eu:main Oct 12, 2026
@openclouders openclouders mentioned this pull request Oct 12, 2026
1 task
@saw-jan saw-jan mentioned this pull request Nov 25, 2026
9 of 22 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUS uploads get stuck when the saved resume URL is no longer valid Sync aborted if TUS HEAD request returns 404

3 participants