Skip to content

Commit

Permalink
Merge pull request #744 from Smithay/fix/destructor_deadlock
Browse files Browse the repository at this point in the history
backend/rs: server: Fix potential deadlock on object destruction
  • Loading branch information
elinorbgr authored Jul 16, 2024
2 parents e3bbf08 + 59398b5 commit 114b16e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 4 additions & 0 deletions wayland-backend/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Bugfixes

- backend/rs: server: Fixed potential deadlock on object destruction

## 0.3.5 -- 2024-07-03

#### Additions
Expand Down
5 changes: 5 additions & 0 deletions wayland-backend/src/rs/server_impl/common_poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ impl<D> InnerBackend<D> {
panic!("An object data was returned from a callback not creating any object");
}
}
// dropping the object calls destructors from which users could call into wayland-backend again.
// so lets release and relock the state again, to avoid a deadlock
std::mem::drop(state);
std::mem::drop(object);
state = self.state.lock().unwrap();
}
DispatchAction::Bind { object, client, global, handler } => {
// temporarily unlock the state Mutex while this request is dispatched
Expand Down
4 changes: 4 additions & 0 deletions wayland-backend/src/server_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,8 +580,12 @@ impl<D> Backend<D> {
}
}

// Workaround: Some versions of rustc throw a `struct is never constructed`-warning here,
// if the `server_system`-feature is enabled, even though the `rs`-module makes use if it.
#[allow(dead_code)]
pub(crate) struct DumbObjectData;

#[allow(dead_code)]
impl<D> ObjectData<D> for DumbObjectData {
#[cfg_attr(coverage, coverage(off))]
fn request(
Expand Down
14 changes: 0 additions & 14 deletions wayland-client/src/event_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,20 +703,6 @@ impl<I: Proxy, U: std::fmt::Debug, State> std::fmt::Debug for QueueProxyData<I,
}
}

struct TemporaryData;

impl ObjectData for TemporaryData {
fn event(
self: Arc<Self>,
_: &Backend,
_: Message<ObjectId, OwnedFd>,
) -> Option<Arc<dyn ObjectData>> {
unreachable!()
}

fn destroyed(&self, _: ObjectId) {}
}

/*
* Dispatch delegation helpers
*/
Expand Down

0 comments on commit 114b16e

Please sign in to comment.