fix: LWS HTTP connection leak, grain index alignment, and reader head tracking

- control_server: add Connection: close header + always return -1 after
  HTTP response to force-close connection. Without this, lws_service()
  blocks forever after the first POST /cmd, freezing the node process loop.
- passthrough: initialize read_index_ to runtime.headIndex when reader
  is added (prevents TOO_EARLY errors on first read)
- passthrough: handle MXL_ERR_OUT_OF_RANGE_TOO_EARLY in addition to
  TOO_LATE (both jump to head index)
- passthrough: use grain_info.index as writer index instead of separate
  write_index_ counter (MXL writers must use TAI-based grain indices)
- passthrough: reduce grain read timeout from 100ms to 20ms for tighter
  loop with LWS poll
- node_runner: add 'status' command handler that sends node status
  back via control server
This commit is contained in:
Johanness
2026-05-26 22:22:46 +03:00
parent 5b2d420e71
commit 3e1477c56c
3 changed files with 26 additions and 14 deletions
+3 -1
View File
@@ -47,12 +47,14 @@ static int send_http_json(struct lws* wsi, const std::string& status, const std:
auto hdr = "HTTP/1.1 " + status + "\r\n"
"Content-Type: application/json\r\n"
"Content-Length: " + std::to_string(body.size()) + "\r\n"
"Connection: close\r\n"
"\r\n";
std::vector<uint8_t> buf(LWS_PRE + hdr.size() + body.size());
std::memcpy(buf.data() + LWS_PRE, hdr.data(), hdr.size());
std::memcpy(buf.data() + LWS_PRE + hdr.size(), body.data(), body.size());
lws_write(wsi, buf.data() + LWS_PRE, hdr.size() + body.size(), LWS_WRITE_HTTP);
return lws_http_transaction_completed(wsi) ? -1 : 0;
lws_http_transaction_completed(wsi);
return -1;
}
struct PerSession {