Skip to content

Commit

Permalink
show the problem and one silly answer
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Dec 19, 2023
1 parent 2a65178 commit c1a2bc8
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion crates/re_sdk/src/log_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ pub trait LogSink: Send + Sync + 'static {
#[derive(Default)]
pub struct BufferedSink(parking_lot::Mutex<Vec<LogMsg>>);

impl Drop for BufferedSink {
fn drop(&mut self) {
for msg in self.0.lock().iter() {
if !matches!(msg, LogMsg::SetStoreInfo(_)) {
re_log::warn!("Dropping data in BufferedSink");
break;
}
}

// TODO: Obviously not the right solution, but shows why and how to fix the problem:
eprintln!(
"BufferedSink forgetting {} messages to avoid GIL deadlock",
self.0.lock().len()
);
std::mem::forget(std::mem::take(&mut *self.0.lock()));

Check failure on line 59 in crates/re_sdk/src/log_sink.rs

View workflow job for this annotation

GitHub Actions / Checks / Rust lints (fmt, check, cranky, tests, doc)

usage of `mem::forget` on `Drop` type
}
}

impl BufferedSink {
/// An empty buffer.
#[inline]
Expand Down Expand Up @@ -134,9 +152,16 @@ impl Drop for MemorySinkStorage {
// warning.
if !matches!(msg, LogMsg::SetStoreInfo(_)) {
re_log::warn!("Dropping data in MemorySink");
return;
break;
}
}

// TODO: Obviously not the right solution, but shows why and how to fix the problem:
eprintln!(
"MemorySinkStorage forgetting {} messages to avoid GIL deadlock",
self.msgs.read().len()
);
std::mem::forget(std::mem::take(&mut *self.msgs.write()));

Check failure on line 164 in crates/re_sdk/src/log_sink.rs

View workflow job for this annotation

GitHub Actions / Checks / Rust lints (fmt, check, cranky, tests, doc)

usage of `mem::forget` on `Drop` type
}
}

Expand Down

0 comments on commit c1a2bc8

Please sign in to comment.