Skip to content

Commit 6e9d7b9

Browse files
committed
WebSocket server now indefinitely keeps track of non-data RPC commands (#8146)
* Fixes #5344
1 parent 1bab0fa commit 6e9d7b9

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

crates/store/re_ws_comms/src/server.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,17 @@ use crate::{server_url, RerunServerError, RerunServerPort};
2828
struct MessageQueue {
2929
server_memory_limit: MemoryLimit,
3030
messages: VecDeque<Vec<u8>>,
31+
32+
/// Never garbage collected.
33+
messages_static: VecDeque<Vec<u8>>,
3134
}
3235

3336
impl MessageQueue {
3437
pub fn new(server_memory_limit: MemoryLimit) -> Self {
3538
Self {
3639
server_memory_limit,
3740
messages: Default::default(),
41+
messages_static: Default::default(),
3842
}
3943
}
4044

@@ -43,6 +47,15 @@ impl MessageQueue {
4347
self.messages.push_back(msg);
4448
}
4549

50+
/// Messages pushed using this method will stay around indefinitely.
51+
///
52+
/// Useful e.g. for `SetStoreInfo` messages, so that clients late to the party actually get a
53+
/// chance of receiving them.
54+
pub fn push_static(&mut self, msg: Vec<u8>) {
55+
self.gc_if_using_too_much_ram();
56+
self.messages_static.push_back(msg);
57+
}
58+
4659
fn gc_if_using_too_much_ram(&mut self) {
4760
re_tracing::profile_function!();
4861

@@ -365,7 +378,13 @@ impl ReceiveSetBroadcaster {
365378
}
366379
});
367380

368-
inner.history.push(msg);
381+
let msg_is_data = matches!(data, LogMsg::ArrowMsg(_, _));
382+
if msg_is_data {
383+
inner.history.push(msg);
384+
} else {
385+
// Keep non-data commands around for clients late to the party.
386+
inner.history.push_static(msg);
387+
}
369388
}
370389

371390
re_smart_channel::SmartMessagePayload::Flush { on_flush_done } => {
@@ -395,6 +414,13 @@ impl ReceiveSetBroadcaster {
395414
// Meaning that if a new one connects, we stall the old connections until we have sent all messages to this one.
396415
let mut inner = self.inner.lock();
397416

417+
for msg in &inner.history.messages_static {
418+
if let Err(err) = client.send(tungstenite::Message::Binary(msg.clone())) {
419+
re_log::warn!("Error sending static message to web socket client: {err}");
420+
return;
421+
}
422+
}
423+
398424
for msg in &inner.history.messages {
399425
if let Err(err) = client.send(tungstenite::Message::Binary(msg.clone())) {
400426
re_log::warn!("Error sending message to web socket client: {err}");

0 commit comments

Comments
 (0)