forge
Explore
Log in

Don't you dare go Hollow

Fix panic in screencopy manager destroyed()

Browse files at this commit

3ccb06f5644c4bcdf74ad2e4d388a13ac65207afIvan MolodetskikhParent: d9e755d
src/protocols/screencopy.rsmodified+16 -1
@@ -449,7 +449,22 @@ where
449 _data: &(),449 _data: &(),
450 ) {450 ) {
451 let state = state.screencopy_state();451 let state = state.screencopy_state();
452- let queue = state.queues.get_mut(manager).unwrap();452+
453+ let Some(queue) = state.queues.get_mut(manager) else {
454+ // This happened once. I'm really not sure how exactly though.
455+ //
456+ // I've dug into wayland-server and wayland-backend, and apparently there are a bunch
457+ // of places where calling destroyed() is delayed (even on a +1 ms timer). Then, it's
458+ // quite possible for some code to run cleanup_queues() *before* this destroyed()
459+ // handler, and delete the queue because the manager is no longer .is_alive() by then.
460+ // Then, queue will be None here.
461+ //
462+ // My attempts to reproduce this in a test have failed though. Perhaps it requires a
463+ // tricky timing condition where the client disconnects at some precise spot inside our
464+ // State::refresh_and_flush_clients() call.
465+ return;
466+ };
467+
453 // Clean up the queue if this was the last object.468 // Clean up the queue if this was the last object.
454 if queue.is_empty() {469 if queue.is_empty() {
455 state.queues.remove(manager);470 state.queues.remove(manager);