Diagnosed Arc sharing issue in SocketBox cloning - complex race condition

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-14 08:03:48 +00:00
parent 5730d2fa0f
commit e3be02db47
4 changed files with 83 additions and 2 deletions

View File

@ -467,7 +467,26 @@ impl NyashInterpreter {
// SocketBox method calls
if let Some(socket_box) = obj_value.as_any().downcast_ref::<SocketBox>() {
return self.execute_socket_method(socket_box, method, arguments);
let result = self.execute_socket_method(socket_box, method, arguments)?;
// 🔧 FIX: Update stored variable for stateful SocketBox methods
// These methods modify the SocketBox internal state, so we need to update
// the stored local variable to ensure subsequent accesses get the updated state
if matches!(method, "bind" | "connect" | "close") {
if let ASTNode::Variable { name, .. } = object {
if let Some(stored_var) = self.local_vars.get_mut(name) {
// Replace the stored instance with the modified one
let updated_instance = socket_box.clone();
let new_box_id = updated_instance.box_id();
let new_is_server = updated_instance.is_server().to_string_box().value == "true";
*stored_var = Box::new(updated_instance);
println!("🔧 Updated local variable '{}' after '{}' - new Box ID: {}, is_server: {}",
name, method, new_box_id, new_is_server);
}
}
}
return Ok(result);
}
// HTTPServerBox method calls