Skip to content

fix: a failed API request no longer terminates the server. - #303

Merged
b4rtaz merged 1 commit into
b4rtaz:mainfrom
cjastone:pr/api-no-terminate
Nov 17, 2026
Merged

b4rtaz merged 1 commit into
b4rtaz:mainfrom
cjastone:pr/api-no-terminate

Conversation

@cjastone

Copy link
Copy Markdown
Contributor

The HTTP accept loop only caught NnTransferSocketException and HttpRequestException. Any other std::exception thrown while handling a request (e.g. a json type error on a syntactically valid but malformed body, or a tokenizer error) propagated out of runHttpServer uncaught and aborted the whole process.

Catch std::exception per connection and keep serving. NnExecutorException and NnConnectionSocketException are rethrown so the existing retry loop in main() still restarts the app when inference or the cluster link is actually broken.

Ported from hellomatik-org/distributed-llama (pi5-cluster, c6c601d), adapted to the extracted http.cpp and its retry-loop semantics.

Tested by building with make dllama-api and running dllama-api with qwen3-30b-a3b q40 (no workers, x86 AVX2). I sent a syntactically valid request with a wrongly typed field, {"messages":[{"role":"user","content":"hi"}],"stream":"yes"}, to /v1/chat/completions. parseInferenceParams calls get() on "stream" and throws a json type_error.

Before this change (main), the process aborts: "terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_3::detail::type_error' what(): [json.exception.type_error.302] type must be boolean, but is string", followed by "Aborted (core dumped)". A following GET /v1/models gets no response because the server is gone.

With this change, the server logs "Request error: [json.exception.type_error.302] type must be boolean, but is string" and keeps running, and a following GET /v1/models returns the model list normally.

The HTTP accept loop only caught NnTransferSocketException and
HttpRequestException. Any other std::exception thrown while handling a
request (e.g. a json type error on a syntactically valid but malformed
body, or a tokenizer error) propagated out of runHttpServer uncaught
and aborted the whole process.

Catch std::exception per connection and keep serving. NnExecutorException
and NnConnectionSocketException are rethrown so the existing retry loop
in main() still restarts the app when inference or the cluster link is
actually broken.

Ported from hellomatik-org/distributed-llama (pi5-cluster, c6c601d),
adapted to the extracted http.cpp and its retry-loop semantics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@b4rtaz
b4rtaz merged commit 7ed1dbe into b4rtaz:main Nov 17, 2026
3 checks passed
@b4rtaz

b4rtaz commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Thanks!

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.

2 participants