Repository navigation
fix(python-sdk): download files over HTTP/1.1 to avoid h2 too_many_data_frames - #2088
Conversation
…ta_frames The sandbox proxy pads file responses with an empty non-final DATA frame every ~32 KiB. h2 (bundled by pyqwest) counts those over a connection's lifetime and closes it with ENHANCE_YOUR_CALM after 100, failing reads of a few MB every time and smaller ones once a pooled connection accumulates the count. Route files.read over the HTTP/1.1 envd transport. Fixes #2027 Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…indows Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Package ArtifactsBuilt from a376b57. Download artifacts from this workflow run. JS SDK ( npm install ./e2b-dockerfile-utils-0.1.2-devin-1793731677-python-downloads-http1.0.tgz ./e2b-2.62.2-devin-1793731677-python-downloads-http1.0.tgzCLI ( npm install ./e2b-cli-2.23.1-devin-1793731677-python-downloads-http1.0.tgzCode Interpreter JS SDK ( npm install ./e2b-code-interpreter-2.9.2-devin-1793731677-python-downloads-http1.0.tgzDesktop JS SDK ( npm install ./e2b-desktop-2.5.1-devin-1793731677-python-downloads-http1.0.tgzPython SDK ( pip install ./e2b_dockerfile_utils-0.1.1+devin.1793731677.python.downloads.http1-py3-none-any.whl ./e2b-2.62.0+devin.1793731677.python.downloads.http1-py3-none-any.whlCode Interpreter Python SDK ( pip install ./e2b_code_interpreter-2.11.7+devin.1793731677.python.downloads.http1-py3-none-any.whlDesktop Python SDK ( pip install ./e2b_desktop-2.7.2+devin.1793731677.python.downloads.http1-py3-none-any.whl |
There was a problem hiding this comment.
TASTE.md review: complies, 0 violations. Checked T-1/T-2 (JS/sync/async parity; the download-only HTTP/1.1 override is a Python-only workaround for a pyqwest h2 limit, applied to both sync and async, and documented on ApiParams.http_version), T-3a (new http_version is keyword-only), T-11 (uses HttpVersion), T-47 (ENVD_API_FILE_DOWNLOAD_HTTP_VERSION is a named constant), T-49 (config precedence unchanged), and T-24/T-48 (files.read formats and stream_idle_timeout unchanged).
…ONS cap Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
🦋 Changeset detectedLatest commit: f8b6b23 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
actually I think global connection limit was okay |
…CONNECTIONS cap" This reverts commit 046b920.
…MAX_CONNECTIONS Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…/2 again (#2197) ## Summary Bumps `pyqwest` `>=0.12.0,<0.13` → `>=0.15.0,<0.16` ([v0.15.0](https://github.com/curioswitch/pyqwest/discussions/308)) and drops the workarounds it makes unnecessary. Lockfiles of `acp-python`, `code-interpreter-python` and `desktop-python` are relocked. - **HTTP/2 downloads (#2027):** pyqwest 0.15 ships h2 with the empty-DATA-frame fix (anuraaga/h2#1, cherry-pick of hyperium/h2#972): empty frames now cost from a budget that payload frames refill, instead of a 100-per-connection lifetime cap. So the #2088 workaround is narrowed: `files.read` in `text`/`bytes` format uses `self._envd_api` on the configured `http_version` (the dedicated `_envd_api_download` client is gone). - **Streamed reads stay on HTTP/1.1:** `ENVD_API_FILE_DOWNLOAD_HTTP_VERSION` becomes `ENVD_API_FILE_STREAM_HTTP_VERSION = "1.1"`, used by `_envd_api_streaming` (sync + async) and, for an explicit async `stream_idle_timeout`, a new `_envd_api_stream` client (previously that branch used `_envd_api`). Over HTTP/2, data a caller hasn't read holds the connection's flow-control window, so a few partly read or abandoned `format="stream"` readers stall every other request on that connection, including envd RPC. - **Upload chunk errors (0.14, curioswitch/pyqwest#287):** an exception raised by the request-body iterator is now re-raised as-is instead of becoming `WriteError`, so `ChunkCheck` (which recorded the `InvalidArgumentException` to re-raise it) is removed. - **Timeouts (0.15, curioswitch/pyqwest#305):** the httpx adapter uses `max(read, write)` instead of `read + write`, so Python SDK timeouts are no longer doubled (SDK-451). This supersedes #2175. - **gevent (0.15, curioswitch/pyqwest#306):** sync calls yield cooperatively under gevent monkey-patching. ## Verification - `test_envd_file_download_empty_data_frames.py` asserts `bytes`/`text` reads use the configured version and streamed reads use HTTP/1.1; the fake server sends 600-byte frames each followed by an empty one (the real proxy sends ~32 KiB per empty frame). It fails on pyqwest 0.12 with `too_many_data_frames` and passes on 0.15. - Real sandbox, buffered reads over HTTP/2 (envd negotiates HTTP/2 via ALPN, checked with a raw pyqwest request): sync and async, 40 sequential text reads and 32 concurrent 4 MiB reads pass; the same script fails with `too_many_data_frames` on pyqwest 0.12. - Real sandbox, streams: with streamed reads on HTTP/2, 3 partly read 8 MiB async streams (`stream_idle_timeout=15`) made the 4th `files.read` and `commands.run` time out. With this PR, 10 such open streams don't block a new read, `commands.run` or `files.list`. - Real sandbox uploads over HTTP/2 (32 concurrent 4 MiB writes, iterator, file object, gzip, `write_files`) pass sync and async, checksums match. - Unit tests: 1047 passed. `files` integration tests: 133 passed, 2 failed (`test_file_symlink`, a backend failure already on `main`, see #2194). Link to Devin session: https://app.devin.ai/sessions/d734c4752b1a4f7b90b09bfd3379c6f4 Open in Devin Desktop: https://app.devin.ai/desktop/session/d734c4752b1a4f7b90b09bfd3379c6f4?variant=devin Requested by: @mishushakov <!-- devin-review-badge-begin --> --- 🟢 Devin Review found nothing to fix · [View findings](https://app.devin.ai/review/e2b-dev/e2b/pull/2197) <a href="https://app.devin.ai/review/e2b-dev/e2b/pull/2197" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a><!-- devin-review-badge-end --> --------- Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: mish@e2b.dev <mish@e2b.dev>
Summary
Fixes #2027. Same change as the closed #2039, rebased on
main. It replaces theAccept-Encoding: identityapproach from #2087, which broke/procand/sysreads on envd 0.10.0.Root cause: httpx asks for gzip by default, so envd gzips file downloads and sends no
Content-Length. Through the sandbox proxy chain, that body reaches HTTP/2 clients with an empty non-final DATA frame after about every 32 KiB. The h2 bundled inpyqwestcounts empty DATA frames over the whole life of a connection and closes it after 100 withENHANCE_YOUR_CALM/too_many_data_frames. So a single read of about 3.2 MB or more always fails, and smaller reads fail once a reused connection has built up enough empty frames. The JS SDK isn't affected: its HTTP/2 client doesn't enforce that limit.Fix:
files.read, sync and async, in every format, now goes over dedicated HTTP/1.1 clients, whateverhttp_versionis set to. Everything else, including uploads, keeps the configured version.This works on every envd version, including gzip reads of
/procfiles.Trade-off: on HTTP/1.1, each in-flight download holds a whole connection. The pool's
E2B_MAX_CONNECTIONScap (default 200) applies per resolved address, and every sandbox shares envd's edge address. So a process can run at most that many downloads at once; any more wait for a connection. The README now says this.Verification
tests/test_envd_file_download_empty_data_frames.py: a local server sends empty DATA frames over h2. It fails withtoo_many_data_frameswithout the fix.Link to Devin session: https://app.devin.ai/sessions/550e475556994f51b1ba7970bc4590f5
Open in Devin Desktop: https://app.devin.ai/desktop/session/550e475556994f51b1ba7970bc4590f5?variant=devin