Title: mcpx(daemon): chat-completions proxy has no upstream timeout and buffers the whole upstream response in memory — proxyToUpstream uses http.DefaultClient and an uncapped TeeReader buffer · Issue #2114 · developing-today/code · GitHub
Open Graph Title: mcpx(daemon): chat-completions proxy has no upstream timeout and buffers the whole upstream response in memory — proxyToUpstream uses http.DefaultClient and an uncapped TeeReader buffer · Issue #2114 · developing-today/code
X Title: mcpx(daemon): chat-completions proxy has no upstream timeout and buffers the whole upstream response in memory — proxyToUpstream uses http.DefaultClient and an uncapped TeeReader buffer · Issue #2114 · developing-today/code
Description: Problem The mcpx daemon's chat-completions reverse proxy (proxyToUpstream, pkgs/mcpx/internal/daemon/routes_proxy.go:215) has no bound on either direction of its upstream call: 1. No upstream timeout. routes_proxy.go:237 calls http.Defau...
Open Graph Description: Problem The mcpx daemon's chat-completions reverse proxy (proxyToUpstream, pkgs/mcpx/internal/daemon/routes_proxy.go:215) has no bound on either direction of its upstream call: 1. No upstream timeo...
X Description: Problem The mcpx daemon's chat-completions reverse proxy (proxyToUpstream, pkgs/mcpx/internal/daemon/routes_proxy.go:215) has no bound on either direction of its upstream call: 1. No upstream t...
Opengraph URL: https://github.com/developing-today/code/issues/2114
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mcpx(daemon): chat-completions proxy has no upstream timeout and buffers the whole upstream response in memory — proxyToUpstream uses http.DefaultClient and an uncapped TeeReader buffer","articleBody":"## Problem\n\nThe mcpx daemon's chat-completions reverse proxy (`proxyToUpstream`, `pkgs/mcpx/internal/daemon/routes_proxy.go:215`) has no bound on either direction of its upstream call:\n\n**1. No upstream timeout.** `routes_proxy.go:237` calls `http.DefaultClient.Do(upReq)`. `http.DefaultClient` has no `Timeout`, and the client sets no `ResponseHeaderTimeout` — the only cancellation is the inbound request's context, i.e. the downstream client disconnecting. The daemon's own HTTP servers set only `ReadHeaderTimeout` (`internal/daemon/server.go:309,361`) — no write/response deadline rescues a stuck handler. An upstream that accepts the connection and never answers (or trickles forever) holds the handler, its goroutine and the downstream connection indefinitely. This is reachable per-request: `handleChatCompletions` takes the upstream URL from the `X-Upstream-Url` request header when present (`routes_proxy.go`, step 4, ~:150), so any local client can aim the daemon at a slow-loris endpoint.\n\n**2. The whole upstream response is buffered in memory, uncapped.** `routes_proxy.go:245-262`: the response body is streamed through an `io.TeeReader` into a `bytes.Buffer`, then `buf.String()` is stored as the feedback interaction record after `io.Copy` finishes. The copy itself streams, but the buffer defeats it — memory grows with the full response size, with no cap. A streamed request makes this worst-case: `chatCompletionReq.Stream` (`routes_proxy.go:38`) is marshalled straight into the proxied payload (`:227`) and `handleChatCompletions` proxies unconditionally (`:164`), so a long SSE stream accumulates in the buffer for its entire life.\n\nVerified on main `42796be5bbe8824545df570f3b239d23d4ef93ac` by reading the code this run.\n\n## The house pattern this misses\n\nEvery other outbound HTTP call in mcpx pins a timeout or a body bound:\n\n- `internal/catalog/embeddings.go:52` — `&http.Client{Timeout: defaults.EmbeddingsRemoteTimeout}`\n- `internal/mcpclient/sse.go:58` — `&http.Client{Timeout: timeout}`; error bodies read via `io.LimitReader(..., defaults.HTTPErrorBodyLimit)` (`sse.go:76,225`)\n- `internal/cli/client.go:118-162` — all daemon clients built with explicit timeouts\n- `internal/daemon/ops.go:285` — registry calls use `cs.Duration(\"registry.timeout\")`\n\n`routes_proxy.go:237` is the only `http.DefaultClient` use in `internal/daemon`.\n\n## Why it matters\n\nThe daemon is the process every other tool call depends on. One hung upstream (a crashed provider gateway, a misconfigured `proxy.upstreamUrl`, a header-aimed slow endpoint) leaks a handler + connection pair forever per request, and one large or streamed response can grow daemon memory without limit — the daemon-side mirror of the inbound body-cap gap in #2082 (request bodies), on the response path #2082 does not cover. Distinct from #2097/#2100/#2102: those are the standalone proxy packages; this is mcpx's own daemon proxy route.\n\n## Acceptance criteria\n\n- [ ] `proxyToUpstream` uses a client with a configured timeout (a `proxy.*` setting with a sane default, in the style of `registry.timeout` / `defaults.EmbeddingsRemoteTimeout`), covering at least time-to-headers and total response time; a timed-out upstream yields a clean 502 to the downstream client.\n- [ ] The feedback-record copy of the upstream response is capped (e.g. `io.LimitReader` at a named constant, in the spirit of `defaults.HTTPErrorBodyLimit`); over-cap responses are still proxied in full to the client, only the recorded copy is truncated, and the truncation is visible in the record.\n- [ ] Tests: a stub upstream that accepts and never responds makes the handler return within the configured timeout; a stub upstream returning an over-cap (or streamed) response is proxied completely while daemon-side buffering stays bounded.\n- [ ] Existing daemon test suites pass unchanged.\n","author":{"url":"https://github.com/dezren39","@type":"Person","name":"dezren39"},"datePublished":"2026-10-29T04:42:24Z","url":"https://github.com/developing-today/code/issues/2114"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:e8c93969-86f9-9e43-e5b9-2264b223cf0e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B87E:1FDCFC:D14EFF:10E638B:6B064265 |
| html-safe-nonce | ea5c9ad888bc1426199213be0802e7f4a5439ba0f8ba09c045833ceb8b907ff8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCODdFOjFGRENGQzpEMTRFRkY6MTBFNjM4Qjo2QjA2NDI2NSIsInZpc2l0b3JfaWQiOiI0NDc1NjU1OTQwNTc4MDk5ODEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 121e1158b088b336f513e0c11e7e1ee3a394605d6c0d03b6f3d7520a940c4e53 |
| hovercard-subject-tag | issue:6092967610 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/developing-today/code/2114/issue_layout |
| twitter:image | https://opengraph.githubassets.com/44a9f51b93d94eeedbe811cc8cb109d3b2981c3c75dbb8ccd40d64f530ca4450/developing-today/code/issues/2114 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/44a9f51b93d94eeedbe811cc8cb109d3b2981c3c75dbb8ccd40d64f530ca4450/developing-today/code/issues/2114 |
| og:image:alt | Problem The mcpx daemon's chat-completions reverse proxy (proxyToUpstream, pkgs/mcpx/internal/daemon/routes_proxy.go:215) has no bound on either direction of its upstream call: 1. No upstream timeo... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dezren39 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1bff4f6bfaa96dc9c42cacf315424c24ebb548b06142ced5e3aaccb2a42dd652 |
| turbo-cache-control | no-preview |
| go-import | github.com/developing-today/code git https://github.com/developing-today/code.git |
| octolytics-dimension-user_id | 26439447 |
| octolytics-dimension-user_login | developing-today |
| octolytics-dimension-repository_id | 627308783 |
| octolytics-dimension-repository_nwo | developing-today/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 627308783 |
| octolytics-dimension-repository_network_root_nwo | developing-today/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ac613d3698d3d8565651455086e1f74da07bf277 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width