Repository navigation
[PR] fix: over-limit request bodies now return a readable 413 instead of ECONNRESET (#3128) - #3138
ranxianglei wants to merge 1 commit into
Conversation
…CONNRESET (#3128) readBody destroyed the socket before the structured 413 could be written, so clients met a bare connection reset on the receive stage while decode/forward stages worked. Stop consuming without destroying (stream pause + TCP backpressure bound the residual), answer receive-stage 413s with Connection: close via respondRequestTooLarge() (residual unread bytes make the connection unusable for keep-alive reuse; Node's destroySoon then feeds the #1982 post-response linger arm for a graceful close), and enrich every request_too_large payload with limitBytes + seenBytes across all three stages. Covers all /__bili/* admin sites sharing readBody, including the handleHostPluginDismiss catch-all that previously answered 400.
📦 Built Package ArtifactBranch: Option A — Install this exact build (recommended)npm install -g billion-context@0.0.3572-pr.3138.3d46e3cThis exact version is immutable and reproducible. The rolling Option B — Download artifact
tar xzf billion-context-pr3138.tgz
npm install -g packageInstall instructions are refreshed on each push. |
(ai: vllm-qwen/qwen3.8-27b) PR #3138 独立审核完成(diff 逐行重读、机制逐条重验、验证重跑;未复用 #3128 讨论里的结论)。 方向关:#3128 要两件事——① 超限时客户端能可靠读到结构化 413;② 字节预算可配置。本 PR 只修 ①,② 明确留待你拍板(config-surface 纪律),方向正确、范围收敛。根因定位成立: 回归清点(diff 触碰路径的既有行为,逐项):
关键机制点(linger arm 声明核实成立):res 'finish' 时戳 lastResponseEndAt(src/server.ts:527);installPostResponseLinger 拦截 end/destroy——新路径 413 响应完成后 Node 的 destroySoon 同 tick 触发 end()+destroy(),两者都被拦下进入 linger:resume() 排空残余接收字节(去掉 RST 诱因)、等对端 FIN、5s backstop 强制关闭。有界、无 fd 泄漏、无新定时器/配置。旧路径裸 destroy() 不走 end(),直接绕过 linger arm——这正是客户端原来看到 RST race 的原因。 测试有效性:
验证证据:
结构化八问:
一个流程提示:PR 正文写的是 "Closes #3128"——合并会自动关掉整个 #3128,包括还在等拍板的 config-budget 那一半。若想留着 #3128 继续谈后半段,请合并前改成 "Partially addresses #3128"(或合并后批准方案时另开一单跟踪)。不影响代码质量判断。 结论:可合并(CI 全绿、合并树已本地验证)。按门禁规则,本 PR 涉及 wire 消息形态变化(413 payload/header),属人工合并类——请你自行合并:#3138 |
|
(ai: zhipuai-lb/glm-5.3) 陈旧票清理(第三批动作①):目标 issue #3128 已关。为避免重复劳动关闭本 PR;如判断有误请直接 reopen 并留言。 |
What this fixes (#3128)
A raw request body over 100 MiB destroyed the client socket BEFORE the structured 413 could be written (
readBodyinsrc/server.ts:req.destroy()thenreject(BodyTooLargeError)). Clients met a bareECONNRESETwhile bili's log recorded a 413 nobody ever received. The decode/forward stages were unaffected (socket still alive there) — only the receive stage.Verified against the reporter's build: the
v0.1.196tag carries exactly this code (src/server.ts:3228-3229 at the tag).Changes
src/server.ts): on overflow it removes its data listener and pauses the stream. The remaining body parks under TCP backpressure (bounded by stream HWM + kernel buffer, no unbounded heap growth), leaving the caller able to write the response.respondRequestTooLarge(res, json)helper: writes the 413 withConnection: close. The header is required, not cosmetic: unread residual body bytes make the connection unusable for keep-alive reuse (the next request would parse over the leftovers). After the response, Node'sdestroySoonroutes through the existing 建议:客户端侧连接请优雅关闭(close_notify+FIN),避免向下游客户端发出 RST #1982 post-response linger arm (graceful peer-close wait, bounded backstop) — no new timers, no new config.src/server/handle.ts) plus all 11/__bili/*admin sites sharingreadBody, includinghandleHostPluginDismisswhose catch-all previously answered over-limit bodies with a 400.request_too_largeerror now carrieslimitBytes+seenBytesin all three stages. The decode stage now reports observed decoded bytes (DecompressedTooLargeErrorgains an optional second ctor arg); the forward stage reports the exact rebuilt size. For the receive stageseenBytesis the count at the crossing, not the full length — the message says so.Behavior changes (old → new)
ECONNRESET/generic failure, 413 unreachable{error:{type:"request_too_large",stage:"receive",message,limitBytes,seenBytes}}+Connection: close{type,stage,message}limitBytes,seenBytes(all three stages)413: request body exceeds N bytes413 [stage]: request body exceeds N bytesNo config-surface changes. The configurable-budget half of #3128 is deliberately NOT in this PR — per the config-surface discipline it needs owner sign-off first (proposal already posted in the issue thread: top-level
limitsblock, defaults = current constants).Tests
tests/request-too-large-receive.test.ts(new, real HTTP): raw 101 MiB POST → the client reads a 413 withstage:"receive"+limitBytes/seenBytes+connection: close; upstream sees ZERO calls; a following small request proxies normally. The fixture teardown uses the sanctionedrestartForceCloseOfseam because the 413'd connection can sit in the 建议:客户端侧连接请优雅关闭(close_notify+FIN),避免向下游客户端发出 RST #1982 linger arm until its backstop (the peer-FIN never arrives after an aborted upload).tests/proxy-readbody.test.ts: rewritten to pin the NEW contract — rejection carries limit+seenBytes, the socket is NOT destroyed, the stream is paused, and late data/end cannot double-settle.npm run typecheckclean. Full-suite verdict = CI on this head.Closes #3128 (bug half; the config-budget half awaits the owner's decision in the issue thread)