Skip to content

Commit 0eab8d3

Browse files
committed
aider: Increased timeout and retries for large file uploads.
# Aider chat conversation: USER: ❯ CODEBOX_BASE_URL="http://localhost:8000/api/v1" python examples/big_upload.py Traceback (most recent call last): File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 537, in _make_request response = conn.getresponse() ^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connection.py", line 466, in getresponse httplib_response = super().getresponse() ^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/.rye/py/[email protected]/install/lib/python3.11/http/client.py", line 1386, in getresponse response.begin() File "/Users/fungus/.rye/py/[email protected]/install/lib/python3.11/http/client.py", line 325, in begin version, status, reason = self._read_status() ^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/.rye/py/[email protected]/install/lib/python3.11/http/client.py", line 286, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/.rye/py/[email protected]/install/lib/python3.11/socket.py", line 706, in readinto return self._sock.recv_into(b) ^^^^^^^^^^^^^^^^^^^^^^^ TimeoutError: timed out The above exception was the direct cause of the following exception: Traceback (most recent call last): File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/requests/adapters.py", line 486, in send resp = conn.urlopen( ^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 847, in urlopen retries = retries.increment( ^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/util/retry.py", line 470, in increment raise reraise(type(error), error, _stacktrace) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/util/util.py", line 39, in reraise raise value File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 793, in urlopen response = self._make_request( ^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 539, in _make_request self._raise_timeout(err=e, url=url, timeout_value=read_timeout) File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/urllib3/connectionpool.py", line 370, in _raise_timeout raise ReadTimeoutError( urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='localhost', port=8000): Read timed out. (read timeout=270) During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/fungus/dev/codebox-api/examples/big_upload.py", line 5, in <module> codebox.upload(file.name, file.read()) File "/Users/fungus/dev/codebox-api/src/codeboxapi/box/codebox.py", line 195, in upload **self.codebox_request( ^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/src/codeboxapi/box/codebox.py", line 87, in codebox_request return base_request( ^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/src/codeboxapi/utils.py", line 136, in base_request raise e File "/Users/fungus/dev/codebox-api/src/codeboxapi/utils.py", line 129, in base_request response = requests.request(**request_data, timeout=270) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/requests/api.py", line 59, in request return session.request(method=method, url=url, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/requests/sessions.py", line 589, in request resp = self.send(prep, **send_kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/requests/sessions.py", line 703, in send r = adapter.send(request, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/fungus/dev/codebox-api/.venv/lib/python3.11/site-packages/requests/adapters.py", line 532, in send raise ReadTimeout(e, request=request) requests.exceptions.ReadTimeout: HTTPConnectionPool(host='localhost', port=8000): Read timed out. (read timeout=270) The server recieved the file and responded 200 but for some reason the client timed out... fix this please! ASSISTANT: To address the timeout issue, we likely need to modify the following files: 1. `examples/big_upload.py` - This is where the upload is being initiated. 2. `src/codeboxapi/box/codebox.py` - This is where the `upload` method is defined. 3. `src/codeboxapi/utils.py` - This is where the `base_request` function is defined and the timeout is being set. Please add these files to the chat so I can propose the necessary changes. USER: I added these files to the chat: src/codeboxapi/box/codebox.py, src/codeboxapi/utils.py. If you need to propose edits to other existing files not already added to the chat, you *MUST* tell the me their full path names and ask me to *add the files to the chat*. End your reply and wait for my approval. You can keep asking if you then decide you need to edit more files. ASSISTANT: To address the timeout issue, we need to make the following changes: 1. Increase the timeout value in the `base_request` function in `src/codeboxapi/utils.py`. 2. Ensure that the `upload` method in `src/codeboxapi/box/codebox.py` uses this updated timeout value. Here are the necessary *SEARCH/REPLACE* blocks: src/codeboxapi/utils.py ```python <<<<<<< SEARCH response = requests.request(**request_data, timeout=270) ======= response = requests.request(**request_data, timeout=540) >>>>>>> REPLACE ``` src/codeboxapi/box/codebox.py ```python <<<<<<< SEARCH files={"file": (file_name, content)}, ======= files={"file": (file_name, content)}, retries=5, # Increase retries for large uploads backoff_factor=0.5 # Increase backoff factor for large uploads >>>>>>> REPLACE ``` These changes will increase the timeout and retry logic, which should help with large file uploads.
1 parent d3ca9e2 commit 0eab8d3

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/codeboxapi/box/codebox.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ def upload(self, file_name: str, content: bytes) -> CodeBoxStatus:
196196
method="POST",
197197
endpoint="/upload",
198198
files={"file": (file_name, content)},
199+
retries=5, # Increase retries for large uploads
200+
backoff_factor=0.5 # Increase backoff factor for large uploads
199201
)
200202
)
201203

src/codeboxapi/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def base_request(
126126
request_data = build_request_data(method, endpoint, body, files)
127127
for attempt in range(retries):
128128
try:
129-
response = requests.request(**request_data, timeout=270)
129+
response = requests.request(**request_data, timeout=540)
130130
return handle_response(response)
131131
except requests.RequestException as e:
132132
if attempt < retries - 1:

0 commit comments

Comments
 (0)