Skip to content

loggerd: widen upload PUT read timeout so a slow-but-successful upload isn't retried forever - #39023

Open
cipherprofessor wants to merge 1 commit into
commaai:masterfrom
cipherprofessor:fix/uploader-read-timeout-retries-forever
Open

cipherprofessor wants to merge 1 commit into
commaai:masterfrom
cipherprofessor:fix/uploader-read-timeout-retries-forever

Conversation

@cipherprofessor

Copy link
Copy Markdown

Fixes #34941.

Root cause

do_upload()'s PUT to the blob store (system/loggerd/uploader.py) used a flat timeout=10. For larger qcamera.ts files over slow/cellular connections, the server receives and stores the file successfully, but takes longer than 10s to send back its ack — requests.put() raises ReadTimeout even though the upload already succeeded (confirmed uploaded, visible in useradmin per the report). Since a file is only tagged as uploaded (via setxattr) on success, the uploader retries the same already-uploaded file forever.

Fix

Added PUT_TIMEOUT = (10, 60), a (connect, read) timeout tuple — keeps the connect side fail-fast (an unreachable host should still fail quickly) while giving the read side more room for a slow-but-successful upload to ack. Left the upload-URL GET a few lines above untouched: the issue's own traceback shows the timeout originating from commadata2.blob.core.windows.net (the blob store), not comma's own API, which the GET hits instead — a categorically different, small metadata request with no comparable delay pattern.

Testing

Added test_upload_put_uses_widened_read_timeout to system/loggerd/tests/test_uploader.py: mocks requests.put, temporarily disables the test suite's default fake_upload short-circuit, calls do_upload() directly on a real generated test file, and asserts the mock was called with timeout=PUT_TIMEOUT.

I wasn't able to run the full test suite end-to-end in my environment — importing uploader.py needs openpilot.common.params, which loads a native libparams_c.dylib built via the project's full SCons graph, and I didn't have a way to build that here (no Linux environment available to me). I did build cereal.messaging's own Cython extension (msgq.ipc_pyx) from scratch and confirmed it imports cleanly, and both edited files pass python3 -m py_compile. As a substitute for the full test run, I wrote a standalone script (not part of this diff) that extracts the real PUT_TIMEOUT value directly from this file's source and exercises it against the actual requests library, using a real local HTTP server that receives a full PUT body and then deliberately delays its response past the old 10s timeout but within the new 60s one: the old value reproduces a real ReadTimeout at exactly 10.0s (matching the reported mechanism), the new value succeeds. Happy to adjust the test or timeout value if there's a preferred approach here.

…d isn't retried forever

do_upload's PUT to the blob store used a flat 10s timeout. For larger
qcamera.ts files over slow/cellular connections, the server receives
and stores the file successfully but takes longer than 10s to ack,
so requests.put raises ReadTimeout even though the upload already
succeeded. Since a file is only tagged uploaded on success, this
makes the uploader retry the same already-uploaded file forever.

Adds PUT_TIMEOUT = (10, 60), a (connect, read) tuple that keeps the
connect side fail-fast while giving the read side more room. The
upload-url GET a few lines above is left untouched -- the issue's own
traceback shows the timeout originating from the blob store host,
not comma's own API, which this GET hits instead.

Fixes commaai#34941.
@github-actions

Copy link
Copy Markdown
Contributor

Process replay diff report

Replays driving segments through this PR and compares the behavior to master.
Please review any changes carefully to ensure they are expected.

✅ 0 changed, 66 passed, 0 errors

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timeout trying to upload qcamera files

1 participant