flm serve: a request body with invalid UTF-8 leaves the NPU locked, and every later request queues forever
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in src/server/server.cpp at handle_request, process_task, the route lambda, the exception catch, and the I/O loop cited in the issue. Reproduce the malformed UTF-8 request and review test_a_body_that_is_not_json_is_refused_and_the_server_keeps_serving from the OpenFlowLM-Next conformance suite. Done means malformed bodies receive 400 responses, the NPU lock is released, and a later NPU request completes.
由索引模型根据 Issue 内容生成。
描述
What happens
One request whose body is not valid JSON and contains an invalid UTF-8 byte takes the NPU lock and never releases it. Every later request to an NPU route (/v1/chat/completions, /api/chat, /api/generate, /v1/embeddings, /v1/audio/transcriptions) waits in the queue until the server is restarted.
flm serve llama3.2:1b
printf '{"messages": "\xe5"' | curl -s -m 10 http://127.0.0.1:52625/v1/chat/completions \
-H 'Content-Type: application/json' --data-binary @-
curl -s -m 60 http://127.0.0.1:52625/v1/chat/completions -H 'Content-Type: application/json' \
-d '{"model":"llama3.2:1b","messages":[{"role":"user","content":"Say ok."}],"max_tokens":8}'
# the second request never completes
The server log shows NPU Locked! for the first request, then invalid UTF-8 byte at index 174, and never NPU Lock Released!.
Expected
A 400 for the malformed body, and the lock released.
Cause
handle_requesttries to parse the body for logging (server.cpp:646-661). The parse fails, sois_jsonstays false, andprocess_taskthen skips its own guarded parse (:689-712).- The route lambda parses the body again with no guard (
:1021-1023). The resultingparse_errorlands in the catch at:782-797. - That catch builds
{"error": "Handler exception: " + e.what()}and calls.dump()(:787). nlohmann quotes the offending bytes ine.what(), and the defaultdump()throwstype_error.316on invalid UTF-8. - The second throw leaves the catch before
process_next_npu_request()runs. It is caught only by the per-I/O-threadtryaroundioc.run()(:502-509), so the lock is never released.
We found a second path to the same leak by reading the source; we did not measure it. request_id is read into a std::string at server.cpp:719, outside every try, while the lock is held. A request with a non-string request_id ("request_id": 5) throws there and leaks the lock the same way. Also from reading the source: each such escape seems to end the ioc.run() loop of the I/O thread it happened on, so the thread pool shrinks by one per request.
Fix we are carrying
safe_dump()dumps withjson::error_handler_t::replace, so building the error body cannot throw. This is ported from OpenFlowLM-Next'sserver.cpp(Vegard Berget).- A small RAII guard releases the NPU lock exactly once on every exit from
process_task, including an exception nothing catches. - A non-string
request_idis refused with a 400 before it is read. - A
json::parse_errorescaping a route lambda is answered with 400 "Invalid JSON".
With the patch, the request above gets a 400, and the log shows NPU Locked! and NPU Lock Released! around it. The next chat request completes.
Environment
FLM v1.0.6 built from the tag, plus one downstream patch that only changes how send_response maps error.code to an HTTP status. That patch does not touch these paths.
Ryzen AI MAX+ 395 (Strix Halo), XDNA2 NPU, 8 columns. NixOS, Linux 7.2.8, amdxdna 0.10, NPU FW 1.1.2.65. Model: llama3.2:1b.
We found this with test_a_body_that_is_not_json_is_refused_and_the_server_keeps_serving from OpenFlowLM-Next's server-api conformance suite.
- 主要语言
- C++
- 星标
- 2.1k
- 派生
- 184
- 平均合并
- 12 小时 22 分钟
- 30 天内合并 PR
- 239
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
ROCm/FastFlowLM 的其他 Issue
-
Update Gemma tokenizer.json after Google's recent fix可能已有人在做 @four1er 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
ROCm/FastFlowLM#1057 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
ROCm/FastFlowLM#757 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
ROCm/FastFlowLM#744 · 2 条评论 ·
维护者通常 1 天内回复
-
Truncated tool call is emitted as a complete one (unterminated heredoc reaches the client)可能已有人在做 @Javinator9889 于 72 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
ROCm/FastFlowLM#741 · 1 条评论 ·
维护者通常 1 天内回复
-
Download timeout可能已有人在做 @stdevPavelmc 于 200 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
ROCm/FastFlowLM#520 · 7 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
difficulty:easy func:gui prio:normal type:bug
难度 2/5 1-3 小时 新手友好度 78/100
NatronGitHub/Natron#2118 ·
维护者通常 1 天内回复
-
Bug
难度 1/5 1 小时以内 新手友好度 82/100
-
bug difficulty:easy prio:low
难度 2/5 1-3 小时 新手友好度 72/100
NatronGitHub/openfx-io#523 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
ArduPilot/ardupilot_gazebo#195 ·