fix: snapshot in-flight stream state

This commit is contained in:
2026-06-21 20:30:01 +09:00
parent 155e039e66
commit 74aca6f6c5
17 changed files with 683 additions and 42 deletions
+19 -1
View File
@@ -14,7 +14,9 @@ use std::time::{SystemTime, UNIX_EPOCH};
use tokio::sync::broadcast;
use protocol::{Alert, AlertLevel, AlertSource, Event};
use protocol::{Alert, AlertLevel, AlertSource, Event, InFlightSnapshot};
use crate::in_flight::{InFlightEvents, snapshot_from_guard};
/// Upper bound on buffered alerts. When exceeded, the oldest
/// entries are discarded so a long-running session cannot leak
@@ -85,6 +87,22 @@ impl Alerter {
let snapshot: Vec<Alert> = buf.iter().cloned().collect();
(snapshot, rx)
}
pub fn subscribe_with_alerts_and_in_flight_snapshot(
&self,
in_flight: &InFlightEvents,
) -> (Vec<Alert>, InFlightSnapshot, broadcast::Receiver<Event>) {
let buf = self
.inner
.buffer
.lock()
.expect("alerter buffer mutex poisoned");
let in_flight_guard = in_flight.snapshot_guard();
let rx = self.inner.event_tx.subscribe();
let alerts: Vec<Alert> = buf.iter().cloned().collect();
let in_flight = snapshot_from_guard(&in_flight_guard);
(alerts, in_flight, rx)
}
}
fn now_ms() -> i64 {
+4 -1
View File
@@ -115,7 +115,9 @@ async fn handle_connection(stream: tokio::net::UnixStream, handle: PodHandle) {
// warnings emitted before this client connected are replayed
// exactly once — they appear in the snapshot, and any alert
// arriving afterwards reaches us through `rx`.
let (alert_snapshot, mut rx) = handle.alerter.subscribe_with_snapshot();
let (alert_snapshot, in_flight, mut rx) = handle
.alerter
.subscribe_with_alerts_and_in_flight_snapshot(&handle.in_flight);
for alert in alert_snapshot {
if writer.write(&Event::Alert(alert)).await.is_err() {
return;
@@ -131,6 +133,7 @@ async fn handle_connection(stream: tokio::net::UnixStream, handle: PodHandle) {
.collect(),
greeting: handle.shared_state.greeting.clone(),
status: handle.shared_state.get_status(),
in_flight,
};
if writer.write(&snapshot_event).await.is_err() {
return;