Skip to content

fix(cloud): a file upload waits at most 600 s for its answer once sent, instead of without end - #733

Merged
rejojer merged 2 commits into
mainfrom
fix/upload-requests-time-out
Dec 1, 2026
Merged

rejojer merged 2 commits into
mainfrom
fix/upload-requests-time-out

Conversation

@rejojer

@rejojer rejojer commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

A cloud file upload (submit_document, Page Classify and Page Split with a PDF path) now waits at most 600 s for the server's answer once its file is sent, instead of waiting without end. Sending the file itself stays unlimited, as before.

Why

Every cloud request the SDK sends has a timeout except the three that upload a file: POST /doc/, POST /classify/ and POST /split/ with a file. requests sets no timeout by default, so if the connection dies silently after the file is sent (a dropped NAT entry, a laptop that sleeps), the call never returns. #720 (Classify) and #716 (documents) found this.

Both propose timeout=(30, 600), which would break large uploads: requests builds a multipart body as one bytes object and urllib3 sends it in one write, so the first number caps sending the whole file, not each block. Measured on a loopback server reading about 6 MB/s, a 20 MB upload:

timeout urllib3 2.8.0 urllib3 1.26.20
none 200 after 3.7 s
(10, 600) 200 after 3.6 s
(1, 600) ConnectionError after 1.0 s ConnectionError after 1.0 s
(None, 1) 200 after 3.7 s 200 after 3.7 s

With (30, 600), a 50 MB scan on a 10 Mbit/s line (about 40 s) would fail at 30 s. That is why #389 left uploads without a timeout.

What changes

  • UPLOAD_TIMEOUT = (None, 600) in cloud_api.py, used by the three uploads: no limit while the file is sent, at most 600 s for the answer after it. The connect attempt keeps the operating system's own limit, as it has now.
  • 600 s is far above what the API takes: it answers an upload once the file is stored and its job queued, and its load balancer closes a request idle for 120 s. The limit only ends a wait on a dead connection.
  • A timed-out upload is not sent again: the session resends a POST only on a 429.
  • urllib3>=1.26.15 (was >=1.26). Older releases send a request on a reused connection under the timeout its previous request left, so the send of an upload would be capped after all: at 30 s after a lookup such as list_collections(), at 600 s after another upload. With requests 2.31, a GET with timeout=0.5 then a 12 MB upload with (None, 600) on one session: ConnectionError after 0.5 s on 1.26.14, 200 after 2.2 s on 1.26.15.

Test plan

  • test_an_upload_the_server_does_not_answer_times_out_and_is_sent_once (document, classify, split): with the time limits cut to 0.3 s, a server that does not answer ends the upload with ReadTimeout after one POST. Fails on main (the upload waits for the answer).
  • test_an_upload_takes_as_long_as_its_file_takes_to_send: a 12 MB upload to a server reading about 6 MB/s succeeds with the connect limit cut to 0.5 s (the read limit to 10 s). Fails with (30, 600) in place of UPLOAD_TIMEOUT.
  • test_cloud_request_wiring no longer asserts that an upload has no timeout.
  • Full suite locally: 1301 passed, 7 skipped. test_summary_effort_ladder_is_what_litellm_would_send and test_litellm_model_settings_list_matches_litellm_model fail the same way on main in this environment (its litellm version).

…t, instead of without end

POST /doc/, /classify/ and /split/ with a file were the only cloud requests
with no timeout, so a connection that died after the file was sent left the
call hanging. They now wait at most 600 s for the answer. Sending the file
stays unlimited: requests sends the body in one write, so a connect timeout
would cap the whole upload and fail a large file on a slow line.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-01T11:31:31.948504Z 8e7b1af New commits
🔒 Security Review ✅ Completed 2026-12-01T11:33:14.159914Z 8e7b1af New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

…ach request's own timeout

urllib3 before 1.26.15 sends a request on a pooled connection under the
timeout its previous request left on the socket. An upload's (None, 600)
then caps sending its file: at 30 s after a lookup such as
list_collections(), at 600 s after another upload. With requests 2.31, a
GET with timeout=0.5 then a 12 MB POST with (None, 600) on one session:
ConnectionError after 0.5 s on 1.26.14, 200 after 2.2 s on 1.26.15.

test_an_upload_takes_as_long_as_its_file_takes_to_send now cuts only the
connect limit to 0.5 s and gives the read limit 10 s. The read timer
starts once the last bytes reach the kernel, so a server still draining a
large send buffer could pass 0.5 s on a busy runner.
@rejojer
rejojer merged commit 01e1ef3 into main Dec 1, 2026
10 checks passed
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.

1 participant