agentscope-ai / agentscope-ai/agentscope-java

[sandbox-e2b] exec timeout is unreliable: readTimeout preempts callTimeout, no server-side kill, cancellation misreported

Đang mở
#2,974 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Java
Star
5.6k
Fork
1.3k
Merge trung bình
4 ngày 12 giờ
Pull request đã merge (30 ngày)
77

Mô tả

## Problem

`E2bEnvdProcessClient.runShellCapture()` timeout handling (`agentscope-extensions/agentscope-extensions-sandbox/agentscope-extensions-sandbox-e2b/src/main/java/io/agentscope/extensions/sandbox/e2b/E2bEnvdProcessClient.java`) has three defects:

1. **Premature false timeout.** The per-call client only sets `callTimeout(timeoutSeconds)` and inherits the base `readTimeout`:

```java
http.newBuilder().callTimeout(timeoutSeconds, TimeUnit.SECONDS).build()
```

If base `readTimeout < timeout` (e.g. custom client `readTimeout=1s`, exec `timeout=3s`), the idle `readTimeout` fires first. The resulting `InterruptedIOException` is caught and wrapped as `ExecTimeoutException("timed out after 3s")`, but only ~1s elapsed.

2. **Timed-out remote process is left running.** `buildEnvdRequest()` sends no `Connect-Timeout-Ms` header, so timeout only disconnects the client HTTP stream. The sandbox process (e.g. `sleep 1000`) keeps running — leak / unexpected billing.

3. **External cancellation misreported as timeout.** `catch (InterruptedIOException)` unconditionally throws `ExecTimeoutException`, even when the thread was interrupted by outer cancellation. The interrupt bit is swallowed.

## Repro

- Base client `readTimeout=1s`, `runShell(..., timeoutSeconds=3)` against a hanging envd stream (`NO_RESPONSE`).
- Expected: `ExecTimeoutException` after ~3s.
- Actual: `ExecTimeoutException` after ~1s with message claiming 3s.

## Expected

- `readTimeout` for the call must stay above `callTimeout` so total-duration semantics wins.
- Send `Connect-Timeout-Ms` when `timeoutSeconds > 0` so envd kills the process server-side.
- If `Thread.currentThread().isInterrupted()`, restore the bit and rethrow instead of wrapping as timeout.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.