Skip to content

runtime/control: refactor to pending message queue#259

Open
npry wants to merge 1 commit into
mainfrom
npry/rt.control.msgqueue
Open

runtime/control: refactor to pending message queue#259
npry wants to merge 1 commit into
mainfrom
npry/rt.control.msgqueue

Conversation

@npry

@npry npry commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Use a pending-message queue for the IPv4/IPv6/self-node messages rather than the tokio notifier in alignment with other actors that work like this. This also avoids spawning and possibly leaking tokio tasks if the control actor dies, and in the expected case (where we've already seen a self-node), no pending work needs to be enqueued at all (previously this would have unconditionally spawned a task).

@nrc nrc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some very small comments inline, happy to land with or without changes

&& !self.pending.is_empty()
{
for req in self.pending.drain(..) {
match req {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style nit: I'd try to refactor this into a send function on the enum

}

if let Some(node) = &self.self_node
&& !self.pending.is_empty()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I don't think this is necessary since the for loop will just be a no-op

let node = node.await;
replier.send(node)
});
self.pending.push(PendingRequest::SelfNode(replier));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These functions seem pretty repetitive and it would be nice to factor out the common 'shape', not sure if that is a good idea though, especially since they're all quite small after this refactor

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would — I thought about it and started sketching something, but I'm not sure exactly what the shape wants to be. I was going to let it cook mentally for a bit and do some research before trying to extract the essence of it. It feels like a common enough problem that there's probably a clean actor-y way to handle it (that Erlang probably already discovered)

@npry npry force-pushed the npry/rt.control.msgqueue branch 2 times, most recently from eec9960 to d4ee0f6 Compare July 1, 2026 00:50
Use a pending-message queue for the IPv4/IPv6/self-node messages rather
than the tokio notifier in alignment with other actors that work like
this. This also avoids spawning and possibly leaking tokio tasks if the
control actor dies, and in the expected case (where we've already seen a
self-node), no pending work needs to be enqueued at all.

Signed-off-by: Nathan Perry <[email protected]>
Change-Id: I0f032c94121fee97b846a4585d89fbee6a6a6964
@npry npry force-pushed the npry/rt.control.msgqueue branch from d4ee0f6 to 24cd6b1 Compare July 1, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants