Files
hakorune/socketbox_issue_new.md
Moe Charm d04f7606e6 fix: Update to new Issue #78 for SocketBox deadlock investigation
- Previous Issue #76 and PR #77 closed and recreated
- New streamlined issue focusing on core deadlock problem
- Multiple Arc<Mutex> hypothesis as primary investigation target
- Ready for systematic root cause analysis

🔥 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-08-14 21:00:14 +09:00

5.2 KiB

🚨 SocketBox Method Call Deadlock - Critical System Failure

Status: 🔥 CRITICAL - Complete SocketBox functionality failure
Impact: Phase 9 HTTP server implementation completely blocked
Priority: Immediate investigation required

📋 Problem Summary

All SocketBox methods (bind(), listen(), isServer(), toString()) cause infinite blocking/deadlock. Other Box types (StringBox, ArrayBox, MapBox) work normally.

🎯 Root Cause Analysis Completed

Confirmed Working Components

  • SocketBox creation: new SocketBox()
  • Arc reference sharing: Arc addresses match = true
  • Clone functionality: Proper Arc sharing

Identified Problem Location

// src/interpreter/expressions.rs:462-464
if let Some(socket_box) = obj_value.as_any().downcast_ref::<SocketBox>() {
    let result = self.execute_socket_method(socket_box, method, arguments)?;
    // ↑ Never reaches this line - execute_socket_method is never called
}

Core Issue: Deadlock occurs in method resolution pipeline BEFORE execute_socket_method is reached.

📊 Evidence from Execution Logs

🔥 Deadlock Reproduction Log

[Console LOG] SocketBox作成完了
[Console LOG] bind実行開始...
🔥 SOCKETBOX CLONE DEBUG: Arc addresses match = true  # ← Clone works fine
# Infinite block here - 🔥 SOCKET_METHOD: bind() called never appears

Normal Box Comparison (ArrayBox)

[Console LOG] ArrayBox作成完了  
[Console LOG] push実行開始...
✅ ARRAY_METHOD: push() called    # ← Method reached normally
✅ ArrayBox push completed        # ← Completes successfully

🧪 Reproduction Test Cases

Test 1: Minimal Deadlock Reproduction

# Command
timeout 10s ./target/release/nyash test_socket_deadlock_minimal.nyash

# Expected: Timeout (deadlock)
# Actual Output:
# [Console LOG] SocketBox作成成功
# [Console LOG] bind()実行開始...
# (infinite block)

Test 2: Other Boxes Normal Operation

# Command
./target/release/nyash test_other_boxes_working.nyash

# Expected: Normal completion
# Actual Output:
# [Console LOG] ✅ ArrayBox正常: size=1
# [Console LOG] ✅ MapBox正常: value=test_value
# [Console LOG] 🎉 他のBox全て正常動作: 4件成功

Test 3: All SocketBox Methods

# Command  
timeout 30s ./target/release/nyash test_socket_methods_comprehensive.nyash

# Expected: Deadlock on first method call
# All methods (toString, isServer, bind, close) should deadlock

🔍 Technical Investigation Required

Primary Hypothesis

SocketBox's unique multiple Arc combination causing circular deadlock:

// SocketBox structure (PROBLEMATIC)
pub struct SocketBox {
    listener: Arc<Mutex<Option<TcpListener>>>,     // Mutex 1
    stream: Arc<Mutex<Option<TcpStream>>>,         // Mutex 2  
    is_server: Arc<Mutex<bool>>,                   // Mutex 3
    is_connected: Arc<Mutex<bool>>,                // Mutex 4
}

// vs Other Boxes (WORKING)
StringBox: Arc<String> only                       // No Mutex
ArrayBox: Arc<Mutex<Vec<T>>> only                 // Single Mutex  
MapBox: Arc<Mutex<HashMap<K,V>>> only             // Single Mutex

Investigation Areas

  1. Lock ordering: Multiple mutex acquisition sequence
  2. Recursive locking: Same mutex re-entry during method resolution
  3. Cross-reference deadlock: Arc reference cycles
  4. Interpreter pipeline: Method resolution vs execution stage bottleneck

🎯 Required Analysis

Systematic Approach Required

  • NO band-aid fixes - Root cause identification essential
  • NO guesswork solutions - Evidence-based analysis only
  • Complete validation - All test cases must pass

Investigation Phases

  1. Architecture Level: Compare SocketBox vs other Box memory/locking patterns
  2. Runtime Level: Method resolution pipeline analysis
  3. Concurrency Level: Arc deadlock detection
  4. Parser/AST Level: If needed, verify AST generation differences

🧪 Test Files Provided

All test files are ready for immediate execution:

  • test_socket_deadlock_minimal.nyash - Minimal reproduction
  • test_socket_methods_comprehensive.nyash - All methods test
  • test_other_boxes_working.nyash - Normal Box operation verification
  • SOCKETBOX_ISSUE_REPRODUCTION.md - Complete reproduction guide

Success Criteria

Must Achieve

# Basic functionality  
./target/release/nyash test_socket_deadlock_minimal.nyash
# Expected: Normal completion, no deadlock

# State management
socket.bind("127.0.0.1", 8080)
socket.isServer()  # Must return true

# All methods working
./target/release/nyash test_socket_methods_comprehensive.nyash  
# Expected: All methods complete successfully

Validation Required

  • Before/After comparison: Detailed behavior analysis
  • Performance impact: Ensure fix doesn't degrade other functionality
  • Memory safety: Maintain Rust safety guarantees
  • Architecture consistency: Solution aligns with "Everything is Box" philosophy

🚨 This issue completely blocks Phase 9 HTTP server implementation. Immediate resolution critical.