YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context
Rust agentsagiaiai-memoryaudio-recordingcomputer-visionhermeshermes-agentllmlocal-ailocal-firstmachine-learningmcpmultimodalopenclawprivacyrewindscreen-recordingspeech-to-textycombinator
fix: server hangs — worker thread starvation + EventManager deadlock
Louis Beaumont2184506621eb
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/main.rs b/apps/screenpipe-app-tauri/src-tauri/src/main.rsindex f9acab737..7dda31c3a 100755--- a/apps/screenpipe-app-tauri/src-tauri/src/main.rs+++ b/apps/screenpipe-app-tauri/src-tauri/src/main.rs@@ -1795,8 +1795,11 @@ async fn main() {.name("screenpipe-server".to_string()).spawn(move || {// Create a dedicated multi-threaded runtime for the server+ // Use 16 worker threads: several are permanently consumed by+ // blocking crossbeam channel calls (audio handlers, meeting watcher),+ // so we need enough headroom for async I/O and HTTP handling.let server_runtime = tokio::runtime::Builder::new_multi_thread()- .worker_threads(4)+ .worker_threads(16).thread_name("screenpipe-worker").enable_all().build()diff --git a/crates/screenpipe-events/src/events_manager.rs b/crates/screenpipe-events/src/events_manager.rsindex 4c3ed250b..bdd7de679 100644--- a/crates/screenpipe-events/src/events_manager.rs+++ b/crates/screenpipe-events/src/events_manager.rs@@ -72,9 +72,12 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for EventSubscription<T> {) -> std::task::Poll<Option<Self::Item>> {let me = self.get_mut();- // Update last_used timestamp when polling- if let Some(manager) = EVENT_MANAGER.subscriptions.write().get_mut(&me.event_name) {- manager.last_used = Instant::now();+ // Update last_used timestamp when polling — use try_write to avoid+ // blocking the async runtime if cleanup is holding the lock.+ if let Some(mut subs) = EVENT_MANAGER.subscriptions.try_write() {+ if let Some(entry) = subs.get_mut(&me.event_name) {+ entry.last_used = Instant::now();+ }}loop {@@ -99,13 +102,14 @@ impl<T: DeserializeOwned + Unpin + 'static> Stream for EventSubscription<T> {impl<T> Drop for EventSubscription<T> {fn drop(&mut self) {- // Remove subscription from manager when dropped- if let Some(manager) = EVENT_MANAGER- .subscriptions- .write()- .get_mut(&self.event_name)- {- manager.last_used = Instant::now();+ // Try to update last_used, but never block.+ // cleanup_stale_subscriptions() holds this write lock while dropping+ // entries via retain() — if Drop also tries to acquire the same lock,+ // parking_lot deadlocks (it's not reentrant for write locks).+ if let Some(mut subs) = EVENT_MANAGER.subscriptions.try_write() {+ if let Some(entry) = subs.get_mut(&self.event_name) {+ entry.last_used = Instant::now();+ }}}}