Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core/supervisor): remove faulty optimization leading to deadlock #103

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions elfo-core/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,11 @@ pub(crate) trait GroupHandle: Send + Sync + 'static {
/// Possible sequences of calls:
/// * `done()`, if handled by a supervisor
/// * `empty()`, if no relevant actors in a group
/// * `visit_last()`, if only one relevant actor in a group
/// * `visit()`, `visit()`, .., `visit_last()`
/// * `visit()`, otherwise
pub trait GroupVisitor {
fn done(&mut self);
fn empty(&mut self, envelope: Envelope);
fn visit(&mut self, object: &ObjectArc, envelope: &Envelope);
fn visit_last(&mut self, object: &ObjectArc, envelope: Envelope);
fn visit(&mut self, object: &ObjectArc, envelope: Envelope);
}

// === SendGroupVisitor ===
Expand Down Expand Up @@ -266,12 +264,7 @@ impl GroupVisitor for SendGroupVisitor<'_> {
self.extra = Some(envelope);
}

fn visit(&mut self, object: &ObjectArc, envelope: &Envelope) {
let envelope = self.extra.take().unwrap_or_else(|| envelope.duplicate());
self.try_send(object, envelope);
}

fn visit_last(&mut self, object: &ObjectArc, envelope: Envelope) {
fn visit(&mut self, object: &ObjectArc, envelope: Envelope) {
self.try_send(object, envelope);
}
}
Expand Down Expand Up @@ -328,12 +321,7 @@ impl GroupVisitor for TrySendGroupVisitor {
self.extra = Some(envelope);
}

fn visit(&mut self, object: &ObjectArc, envelope: &Envelope) {
let envelope = self.extra.take().unwrap_or_else(|| envelope.duplicate());
self.try_send(object, envelope);
}

fn visit_last(&mut self, object: &ObjectArc, envelope: Envelope) {
fn visit(&mut self, object: &ObjectArc, envelope: Envelope) {
self.try_send(object, envelope);
}
}
18 changes: 8 additions & 10 deletions elfo-core/src/supervisor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
actor::{Actor, ActorMeta, ActorStatus},
config::{AnyConfig, Config, SystemConfig},
context::Context,
envelope::Envelope,
envelope::{Envelope, EnvelopeOwned},
exec::{Exec, ExecResult},
group::{RestartMode, RestartPolicy, TerminationPolicy},
message::Request,
Expand Down Expand Up @@ -218,11 +218,11 @@ where

match outcome {
Outcome::Unicast(key) => match get_or_spawn!(self, key) {
Some(object) => visitor.visit_last(&object, envelope),
Some(object) => visitor.visit(&object, envelope),
None => visitor.empty(envelope),
},
Outcome::GentleUnicast(key) => match self.objects.get(&key) {
Some(object) => visitor.visit_last(&object, envelope),
Some(object) => visitor.visit(&object, envelope),
None => visitor.empty(envelope),
},
Outcome::Multicast(list) => {
Expand Down Expand Up @@ -251,14 +251,12 @@ where
return visitor.empty(envelope);
}

loop {
let object = iter.next().unwrap();
if iter.peek().is_none() {
return visitor.visit_last(&object, envelope);
} else {
visitor.visit(&object, &envelope);
}
for item in iter {
visitor.visit(&item, envelope.duplicate());
}

let (_, token) = envelope.unpack_request();
token.forget();
}

fn spawn(self: &Arc<Self>, key: R::Key, mut backoff: Backoff) -> Option<ObjectArc> {
Expand Down
8 changes: 1 addition & 7 deletions elfo-network/src/worker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,7 @@ impl SocketReader {
// TODO: maybe emit some metric?
}

fn visit(&mut self, object: &ObjectArc, envelope: &Envelope) {
let envelope = envelope.duplicate();
self.this
.do_handle_message(self.flows, object, envelope, true);
}

fn visit_last(&mut self, object: &ObjectArc, envelope: Envelope) {
fn visit(&mut self, object: &ObjectArc, envelope: Envelope) {
self.this
.do_handle_message(self.flows, object, envelope, true);
}
Expand Down