Skip to content

refactor(lease): Remove Arc::get_mut anti-pattern from lease injection #211

@JoshuaChi

Description

@JoshuaChi

Problem

Current lease injection in NodeBuilder::build() uses Arc::get_mut() pattern which is fragile:

// d-engine-server/src/node/builder.rs#L234-259
let mut state_machine: Arc<SM> = self.state_machine.take()?;

if let Some(sm) = Arc::get_mut(&mut state_machine) {
    sm.try_inject_lease(lease_config)?;
} else {
    // CRITICAL error if Arc is cloned
    return Err("State machine Arc must have single ownership");
}

Issues:

  1. Logical contradiction: Comment says "injected before Arc wrapping", but state_machine is already Arc<SM>
  2. Fragile API: Fails with CRITICAL error if Arc is cloned before build()
  3. Anti-pattern: Violates Rust ownership - shouldn't mutate after Arc wrapping

Metadata

Metadata

Assignees

No one assigned

    Labels

    type:refactorCode restructuring without changing external behavior

    Type

    Projects

    Status

    Done

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions