Skip to content

fix(xhttp): rewrite libx bench servers on current API + h2 on_data arg fix - #88

Merged
mivinci merged 1 commit into
mainfrom
codebuddy/bench-libx-fixes
Aug 26, 2026
Merged

mivinci merged 1 commit into
mainfrom
codebuddy/bench-libx-fixes

Conversation

@mivinci

@mivinci mivinci commented Aug 26, 2026

Copy link
Copy Markdown
Owner

背景

libx/bench/http/ 的 4 个 C++ bench server(http/https/ws/wss)仍使用 pre-resolver
旧 server API(xHttpServerCreate()、xHttpServerRoute()、xHttpResponseWriter/
xHttpResponseSend),在新 API 下无法编译(X_BUILD_BENCHMARKS=ON 即挂)。CI 默认
不开 bench 所以一直没暴露;本次压测工作开启 bench 后才发现。

改动

  • 4 个 bench server 重写到新 API:xHttpMux resolver + xHttpRouteInfo
    回调 + xHttpCtx handler;POST /echo 用 xHttpCtxSetUser 存 per-request 状态。
  • 修复 h2 on_data arg bug(proto_h2.c):h2 直接传 route_info->arg,
    h1 用 stream->user ?: route_info->arg——per-request 状态在 h2 下不可见,
    POST body 处理解引用 NULL 崩溃。对齐 h1。
  • bench per-request 状态泄漏修复:POST /echo 的 EchoBody 在
    on_done(正常)和 on_close(abort/断开兜底)双路径释放;
    xHttpRouteConf 补 on_close 字段并在 xHttpMuxHandle 转发。

验证

  • 4 个 server 全部构建 + 功能冒烟通过(HTTP/HTTPS 的 h1+h2 GET/POST、WS/WSS 升级 101)
  • ASan 下正常 POST / 半途断开 / RST abort 均无 double-free / UAF
  • 300 次 RST abort POST 后 RSS 稳定(7680→7696KB),无泄漏
  • h2 修复后 curl -sk POST(默认协商 h2)正常 echo

详见 issues/http-h2-ondata-user-arg.md。

The four C++ bench servers in libx/bench/http used the pre-resolver
server API (xHttpServerCreate(), xHttpServerRoute(),
xHttpResponseWriter/xHttpResponseSend) which no longer exists — they
did not compile when X_BUILD_BENCHMARKS=ON. Rewrite them on the current
API (xHttpMux resolver + xHttpCtx handlers) and fix two bugs found
while doing so:

- proto_h2.c: the h2 on_data callback passed route_info->arg instead
  of stream->user, so per-request state (xHttpCtxSetUser) was
  invisible and POST body handlers dereferenced NULL. Align with h1.
- bench POST /echo per-request state is now freed on both on_done and
  on_close (abort-path leak guard); xHttpRouteConf gained on_close,
  forwarded by xHttpMuxHandle.
@mivinci
mivinci merged commit 4216dc6 into main Aug 26, 2026
28 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant