Skip to content

armgit / E2B

Public Imported from GitHub
0

Open-source, secure environment with real-world tools for enterprise-grade agents.

Limit hanging stream timeout (#1197)

Tomas Valenta710fae6fa188
diff --git a/.changeset/tasty-worms-count.md b/.changeset/tasty-worms-count.md
new file mode 100644
index 000000000..e99c3cd6a
--- /dev/null
+++ b/.changeset/tasty-worms-count.md
@@ -0,0 +1,5 @@
+---
+'@e2b/python-sdk': patch
+---
+
+request_timeout applies to connect/pool/write
diff --git a/packages/python-sdk/e2b_connect/client.py b/packages/python-sdk/e2b_connect/client.py
index 61ebb6fb9..b41fedb03 100644
--- a/packages/python-sdk/e2b_connect/client.py
+++ b/packages/python-sdk/e2b_connect/client.py
@@ -322,11 +322,17 @@ class Client:
data = self._codec.encode(req)
flags = EnvelopeFlags(0)
- extensions = (
- None
- if request_timeout is None
- else {"timeout": {"connect": request_timeout, "pool": request_timeout}}
- )
+ timeout_ext = {}
+ if request_timeout is not None:
+ timeout_ext["connect"] = request_timeout
+ timeout_ext["pool"] = request_timeout
+ timeout_ext["write"] = request_timeout
+ if timeout:
+ # This is not actually timeout for the whole stream read, but timeout from the last read chunk.
+ # At worst then, the timeout of a hanging stream could be 2 * timeout (reading body until timeout-ϵ, then waiting for the read timeout).
+ # However, this is still better than no timeout at all and the full timeout in sync python might be way more complicated.
+ timeout_ext["read"] = timeout
+ extensions = {"timeout": timeout_ext} if timeout_ext else None
if self._compressor is not None:
data = self._compressor.compress(data)