Skip to content

fix(contents): time out Contents API requests instead of hanging forever - #279

Open
GongYuanCaiJi wants to merge 1 commit into
googlecolab:mainfrom
GongYuanCaiJi:fix/contents-request-timeout
Open

GongYuanCaiJi wants to merge 1 commit into
googlecolab:mainfrom
GongYuanCaiJi:fix/contents-request-timeout

Conversation

@GongYuanCaiJi

Copy link
Copy Markdown

ContentsClient._request calls requests.request() with no timeout, so a dropped connection makes colab upload / colab download (and ls / rm / edit) hang forever. This passes a (connect, read) timeout of (30, 300) seconds. The read timeout bounds the gap between bytes, not the whole transfer, so large files still complete.

Fixes #252

Repro / test: test_request_times_out_when_server_stops_responding points the client at a local socket that accepts the connection and never answers.

Before (on main):

>       assert not worker.is_alive(), "request hung with no timeout"
E       AssertionError: request hung with no timeout
1 failed, 6 passed in 10.45s

After:

tests/test_contents.py .......
7 passed in 1.46s

Full suite: 587 passed, 19 skipped; ruff check . clean. The four existing assert_called_once_with checks now include timeout=REQUEST_TIMEOUT, and docs/03_file_management.md documents the timeout.

ContentsClient._request called requests.request() with no timeout, so a
dropped connection made `colab upload`/`download` (and ls/rm/edit) hang
indefinitely. Pass a (connect, read) timeout of (30, 300) seconds; the read
timeout bounds the gap between bytes, so large transfers still complete.

Adds a test with a local server that accepts but never responds: it hangs
on main and now fails fast with requests.exceptions.Timeout.

Fixes: googlecolab#252
@google-cla

google-cla Bot commented Nov 24, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@sethtroisi

Copy link
Copy Markdown
Collaborator

Looks reasonable.

One note the test needs to be <50ms so if it actually waits 1 or 10 seconds for the timeout that will need to be changed.

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.

2 participants