Fix SocketBox deadlock: Remove double-mutex lock in clone debug code

Co-authored-by: moe-charm <217100418+moe-charm@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2025-08-14 12:26:46 +00:00
parent 80c911d3c8
commit 06694296a7
2 changed files with 41 additions and 23 deletions

View File

@ -56,33 +56,13 @@ pub struct SocketBox {
impl Clone for SocketBox {
fn clone(&self) -> Self {
eprintln!("🔥 SOCKETBOX CLONE DEBUG:");
eprintln!("🔥 Original Socket ID = {}", self.base.id);
eprintln!("🔥 Original Arc pointer = {:p}", &self.is_server);
eprintln!("🔥 Arc strong_count BEFORE = {}", std::sync::Arc::strong_count(&self.is_server));
let cloned = Self {
Self {
base: BoxBase::new(), // New unique ID for clone (for debugging/identity)
listener: Arc::clone(&self.listener), // Share the same listener
stream: Arc::clone(&self.stream), // Share the same stream
is_server: Arc::clone(&self.is_server), // 🔧 Share the same state container
is_connected: Arc::clone(&self.is_connected), // 🔧 Share the same state container
};
eprintln!("🔥 Cloned Socket ID = {}", cloned.base.id);
eprintln!("🔥 Cloned Arc pointer = {:p}", &cloned.is_server);
eprintln!("🔥 Arc strong_count AFTER = {}", std::sync::Arc::strong_count(&self.is_server));
eprintln!("🔥 Arc addresses match = {}",
std::ptr::eq(&*self.is_server as *const _, &*cloned.is_server as *const _));
// 状態共有テスト
if let (Ok(orig_guard), Ok(clone_guard)) = (self.is_server.lock(), cloned.is_server.lock()) {
eprintln!("🔥 Original state = {}", *orig_guard);
eprintln!("🔥 Cloned state = {}", *clone_guard);
eprintln!("🔥 States match = {}", *orig_guard == *clone_guard);
is_server: Arc::clone(&self.is_server), // Share the same state container
is_connected: Arc::clone(&self.is_connected), // Share the same state container
}
cloned
}
}

View File

@ -0,0 +1,38 @@
# test_socketbox_fix_validation.nyash
# ✅ Validation test for SocketBox deadlock fix
static box Main {
init { console }
main() {
me.console = new ConsoleBox()
me.console.log("🎯 SocketBox Deadlock Fix Validation")
local socket = new SocketBox()
me.console.log("✅ SocketBox created successfully")
# Test 1: Basic method calls that were deadlocking
me.console.log("Test 1: toString() method...")
local str = socket.toString()
me.console.log("✅ toString() success: " + str)
me.console.log("Test 2: isServer() before bind...")
local isServerBefore = socket.isServer()
me.console.log("✅ isServer() before: " + isServerBefore.toString())
me.console.log("Test 3: bind() method...")
local bindResult = socket.bind("127.0.0.1", 18888)
me.console.log("✅ bind() success: " + bindResult.toString())
me.console.log("Test 4: isServer() after bind...")
local isServerAfter = socket.isServer()
me.console.log("✅ isServer() after: " + isServerAfter.toString())
me.console.log("Test 5: close() method...")
local closeResult = socket.close()
me.console.log("✅ close() success: " + closeResult.toString())
me.console.log("🎉 All SocketBox methods working without deadlock!")
return "SOCKETBOX_FIX_VALIDATED"
}
}