e2b-dev / e2b-dev/runtime

api: ReadTimeout: 10s kills body reads under high concurrency, conflicting with requestTimeout: 70s

Open Beginner friendly
#3,415 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
1.6k
Forks
438
PR merge metrics
No merged PRs in 30d

Description

Problem

Under high concurrency (e.g. 1 000 simultaneous sandbox creates) the API returns a flood of errors with:

reading failed: read tcp 192.168.0.146:3000->...: i/o timeout

Root cause

packages/api/main.go configures two competing timeouts:

Setting Value Scope
ReadTimeout 10 s Starts at TCP accept; covers headers + body
requestTimeout 70 s Context deadline applied by middleware

Go's http.Server.ReadTimeout starts counting from the moment the TCP connection is accepted — including scheduler queue time. Under high concurrency, goroutines may wait >10 s in the scheduler before they ever execute and call io.ReadAll. By then the ReadTimeout has already fired and the connection is dead.

requestTimeout: 70 s is the intended per-request ceiling but is never reached in practice because ReadTimeout: 10s fires first.

Why ReadHeaderTimeout is sufficient

ReadHeaderTimeout: 5s already guards against slowloris (headers never arrive). Once headers are received and ServeHTTP starts, request bodies on this API are small JSON payloads (<1 KB) sent in a single TCP segment — there is no meaningful slow-body attack surface. The requestTimeout: 70s middleware context provides the actual per-request deadline for handler execution.

Fix

Remove ReadTimeout from the http.Server config. Keep ReadHeaderTimeout for slowloris protection.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in packages/api/main.go and inspect the http.Server timeout configuration, especially ReadTimeout, ReadHeaderTimeout, and the requestTimeout middleware described in the issue. Done means removing ReadTimeout while retaining ReadHeaderTimeout and the 70-second request deadline, then verifying the API builds and its existing tests pass.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
api, backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.