From 198845f1765aa7da3f9ff29e58da7522c3ff0d55 Mon Sep 17 00:00:00 2001 From: Nadja Reitzenstein Date: Wed, 18 Jan 2023 17:38:32 +0100 Subject: [PATCH] Fix deadlock (whoops) --- bffhd/actors/mod.rs | 9 ++++++++- bffhd/actors/process.rs | 7 ------- bffhd/capnp/machine.rs | 4 +--- bffhd/resources/mod.rs | 26 ++++++++++++++------------ 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/bffhd/actors/mod.rs b/bffhd/actors/mod.rs index a1ca01d..ae64ee4 100644 --- a/bffhd/actors/mod.rs +++ b/bffhd/actors/mod.rs @@ -68,6 +68,7 @@ where fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll { // Work until there is no more work to do. loop { + tracing::trace!("polling actor driver"); // Poll the `apply` future. And ensure it's completed before the next one is started match self .future @@ -89,9 +90,15 @@ where Poll::Pending => return Poll::Pending, Poll::Ready(None) => return Poll::Ready(()), Poll::Ready(Some(state)) => { + tracing::trace!(?state, "actor driver received state update"); // This future MUST be polled before we exit from the Actor::poll because if we // do not do that it will not register the dependency and thus NOT BE POLLED. - let f = self.actor.apply(state); + let f = if self.first { + self.first = false; + self.actor.restore(state) + } else { + self.actor.apply(state) + }; self.future.replace(f); } } diff --git a/bffhd/actors/process.rs b/bffhd/actors/process.rs index 2dca118..7d8b0f0 100644 --- a/bffhd/actors/process.rs +++ b/bffhd/actors/process.rs @@ -28,13 +28,6 @@ impl Process { pub fn into_boxed_actuator(self) -> Box { Box::new(self) } - - fn build_command(&mut self, state: &ArchivedValue, extra_args: I) -> Command - where - I: IntoIterator, - S: AsRef, - { - } } impl Actor for Process { diff --git a/bffhd/capnp/machine.rs b/bffhd/capnp/machine.rs index 3038a71..d1c6bdf 100644 --- a/bffhd/capnp/machine.rs +++ b/bffhd/capnp/machine.rs @@ -177,9 +177,7 @@ impl InUseServer for Machine { _: inuse::SendRawDataResults, ) -> Promise<(), ::capnp::Error> { let data: Vec = pry!(pry!(params.get()).get_data()).to_vec(); - let resource = self.resource.clone(); - let session = self.session.clone(); - resource.send_raw(data); + self.resource.send_raw(data); Promise::ok(()) } } diff --git a/bffhd/resources/mod.rs b/bffhd/resources/mod.rs index 18f4d7a..6034e7d 100644 --- a/bffhd/resources/mod.rs +++ b/bffhd/resources/mod.rs @@ -179,19 +179,21 @@ impl Resource { pub fn send_raw(&self, data: Vec) { let mut serializer = AllocSerializer::<1024>::default(); - let old_state_ref = self.inner.get_state_ref(); - let old_state: &ArchivedState = old_state_ref.as_ref(); - let m_state: MachineState = - match Deserialize::::deserialize(&old_state.inner, &mut serializer) { - Ok(s) => s, - Err(error) => { - tracing::error!(?error, "failed to deserialize stored state!"); - return; - } - }; + let archived = { + let old_state_ref = self.inner.get_state_ref(); + let old_state: &ArchivedState = old_state_ref.as_ref(); + let m_state: MachineState = + match Deserialize::::deserialize(&old_state.inner, &mut serializer) { + Ok(s) => s, + Err(error) => { + tracing::error!(?error, "failed to deserialize stored state!"); + return; + } + }; - let _ = serializer.serialize_value(&State::with_raw(m_state, data)); - let archived = ArchivedValue::new(serializer.into_serializer().into_inner()); + let _ = serializer.serialize_value(&State::with_raw(m_state, data)); + ArchivedValue::new(serializer.into_serializer().into_inner()) + }; self.inner.set_state(archived); }