Most HTTP handlers return a bare Req from init/2: the request process crashes after the reply and the connection stays open #27
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Purpose (fix): every HTTP request ends cleanly. Today most handlers' request processes crash after the reply, and the connection is left open despite
connection: close.Found while probing #26 (Saturnus, 2026-12-01), on main
c191c6b; the code is the same on15752f4.What happens. Cowboy's
init/2must return{ok, Req, State}. 15 of the 17*_api.erlhandlers return the replyReqalone (mcl_rag_http:ok_json/2and the rest return aReq): add_knowledge, answer_query, classify_topics, detect_corpus_change, embed_document, get_chunk_by_id, get_source_by_id, ingest_document, list_chunks_by_source, list_sources_page, prune_chunks, rerank_results, retire_document, schedule_reembed, upload_knowledge. Only search_chunks_semantic and seed_corpus return{ok, Req, State}.The reply is sent first, so callers get the right status and body. Then
cowboy_handler:execute/2fails withtry_clauseon the returned map. Every such request:Ranch listener mcl_rag_http_listener ... exit with reason {{try_clause, ...);connection: close. In a probe on a CT listener, 203 of 203 requests to/api/rag/chunks/by-sourceand/api/rag/knowledge/addnever closed; each client read had to time out.Why it matters. A client that reads until close (instead of by content-length) hangs. Every call costs an error report in the log, which hides real crashes. Open connections pile up until Cowboy's idle timeout.
Done when:
init/2returns{ok, Req, State}.Req: for example, a request withconnection: closeto each route must see the socket closed promptly, and notry_clausereport is logged.Refs #26
Done-when, read on main
9b83f9eb9c(PR 29, Jupiter PASS r1):init/2returns{ok, Req, State}: all 17 handlers (9b83f9e).fec5619) sends a request withconnection: close, waits for the socket to close, and checks that nothing is logged at error level. A handler reverted to a bareReqturns its own case red (Jupiter's mutant read).CI on the tip: c4-model 6413, lint 6414.