Repository navigation
Description
Hi,
I found this while writing the transfer tests for #217. I've kept it separate because that PR only adds tests.
Short Information
- Used Device: N/A (found by reading the code and testing with a mocked server)
- Used Toolkit version: 3.0.6 (
mainat 7d4ede0) - Operating System: Linux
Problem Definition Briefly
In UploadManager.upload(), a failed POST is caught and printed, and then the loop carries on:
except requests.exceptions.HTTPError as e:
print(e.response.text)
By that point the chunk has already been read from the file, but offset hasn't moved on. The next pass reads the following chunk and sends it with the old offset, so the failed chunk is never resent.
Expected Output
A failed POST reaches the retry logic in uploader.py, which fetches the offset from the server, waits and resumes, or gives up after its retry limit. That can't happen at the moment, because upload() never lets the HTTP error out.
Actual Output
With requests.post mocked, an 8-byte file and 2-byte chunks:
One 500 on the second chunk, then success:
bytes=0-8/8 aa OK
bytes=2-8/8 bb 500
bytes=2-8/8 cc OK <- wrong offset, bb is never resent
bytes=4-8/8 dd OK
bytes=6-8/8 (empty) OK, returns the hash
With a 4-byte file, 2-byte chunks and a server that always fails, the loop kept sending bytes=0-4/4 with an empty chunk, with no wait between requests, until my test stopped it after 12 requests. Nothing in the loop would end it.
Extra information
I haven't tested this against the real server, and I don't have the image-server handler, so what happens next depends on what it does:
- If it checks the start of the range against its stored offset, the later chunks fail as well and the client ends up in the endless loop.
- If it doesn't check, the upload could finish with a chunk missing and still return a hash.
Could you tell me which it is?
The simplest fix looks like removing the except, so the error reaches the existing retry logic. I haven't tested that. One thing to check is that is_retriable_exception treats most 4xx responses as not retriable, so those would stop the upload with an error rather than retrying. That seems right to me, but it's your call.
I'm happy to send a PR with a test if you'd like one, or to leave it with you.
This was found with Claude Code, and I've checked the results myself.
Thanks, Chris
Activity
ozcan-durak commentedon Nov 5, 2026
Confirmed in the handler: it checks the stored file size against the start offset, but that can't detect a skipped chunk if the next chunk arrives with the old offset. The client needs to stop on the HTTP error and let the existing retry code fetch the server offset again.
I'll put the fix and regression tests in a separate PR and hold 3.0.7 until it's covered.
ozcan-durak commentedon Nov 5, 2026
@chrisdebian the fix is in #220. The failed request now goes back through the existing offset/retry path. Both cases preserve the file bytes: the failed chunk wasn't stored, or it was stored before the 500 response.
Could you take a look before we roll it into 3.0.7?