horizon-server events: a stream starts when it's asked for, not when its headers are out

An event emitted between the reply's headers and the stream's first read of the
cursor was skipped (CI caught it in a_stream_sends_what_happens).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Ludovic MarieandClaude Opus 5.5 committed 2026-10-31 15:37:22 +01:00
1 parent 48ccd93267
commit bef1eff277
1 file changed
+3 -2
+3 -2
View File
@@ -133,11 +133,12 @@ pub fn route(shared: &Arc<Shared>, request: &Request) -> Response {
.after(since.unwrap_or(0), &wanted);
return Response::json(200, &json!({ "next": last, "events": events }));
}
// Without a number, the stream starts with the request: what happens while the reply's headers go out
// is sent.
let mut cursor = since.unwrap_or_else(|| shared.events.lock().unwrap().last);
let shared = shared.clone();
let mut response = Response::text(200, "text/event-stream", "");
response.stream = Some(Box::new(move |mut stream| {
// Without a number, the stream starts now.
let mut cursor = since.unwrap_or_else(|| shared.events.lock().unwrap().last);
let mut quiet_since = Instant::now();
loop {
let events = {