## 🎯 Problem Identification Complete - SocketBox method calls (bind, isServer, toString) cause infinite blocking - Root cause: Method resolution pipeline deadlock before execute_socket_method - Other Box types (ArrayBox, StringBox, MapBox) work normally - Arc<Mutex> reference sharing confirmed working (Arc addresses match = true) ## 🔧 Debug Infrastructure Added - Comprehensive debug logging in socket_box.rs (bind, isServer, clone, toString) - Method call tracing in http_methods.rs - Deadlock detection points identified at interpreter expressions.rs:462-464 ## 📋 Issue #76 Created for Copilot Investigation - Systematic root cause analysis requirements (Architecture→Parser→Runtime levels) - Comprehensive test cases: minimal/comprehensive/comparison scenarios - Strict prohibition of band-aid fixes - architectural analysis required - Hypothesis: Multiple Arc<Mutex> combinations causing circular deadlock ## 🧪 Test Suite Added - test_socket_deadlock_minimal.nyash: Minimal reproduction case - test_socket_methods_comprehensive.nyash: All methods deadlock verification - test_other_boxes_working.nyash: Normal Box operation confirmation - SOCKETBOX_ISSUE_REPRODUCTION.md: Complete reproduction guide ## 📊 Impact Assessment - Phase 9 HTTP server implementation completely blocked - SocketBox functionality entirely non-functional - Critical blocker for production readiness - Requires immediate systematic investigation 🔥 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
4.3 KiB
4.3 KiB
🔴 Critical Issue: Phase 9実用化ブロッカー
優先度: 🔴 最高(実用性ブロッカー)
期間: 1週間
前提: Phase 9 (PR #67) マージ済み
🎯 概要
Phase 9で実装されたWASM/AOTとHTTPサーバー機能に重大な制約があり、実用化を阻害しています。本issueではこれらを修正し、真の実用レベルに到達させます。
🔍 現在の問題
1. WASM/AOT コンパイルエラー(最重要)
# 現象
$ ./target/release/nyash --compile-wasm test_simple_loop.nyash
❌ WASM compilation error: Unsupported instruction: Jump { target: BasicBlockId(1) }
原因: src/backend/wasm/codegen.rsにJump/Branch命令が未実装
影響: ループ・条件分岐を含む全プログラムがWASM/AOT化不可
2. HTTPServerBox listen()常に失敗
// 現象
server.bind("127.0.0.1", 8080) // ✅ true
server.listen(10) // ❌ always false
原因: src/boxes/socket_box.rsのlisten()実装が不完全
影響: HTTPサーバーが実際には動作しない
3. エラーハンドリング脆弱性
$ grep -n "unwrap()" src/boxes/http_server_box.rs | wc -l
26
原因: 26箇所のunwrap()使用 影響: 本番環境でパニック多発の可能性
📋 実装タスク
Task 1: WASM Jump/Branch命令実装(2日)
ファイル: src/backend/wasm/codegen.rs
// 追加実装箇所(358行目付近)
MirInstruction::Jump { target } => {
// 無条件ジャンプ
// WASMのbr命令を使用
Ok(vec![
format!("br $block_{}", target.0),
])
},
MirInstruction::Branch { cond, then_block, else_block } => {
// 条件分岐
// WASMのbr_if命令を使用
self.emit_value_load(cond)?;
Ok(vec![
"i32.eqz".to_string(),
format!("br_if $block_{}", else_block.0),
format!("br $block_{}", then_block.0),
])
},
必要な補助実装:
- ブロック深度管理(
get_block_depthメソッド) - ループ構造のblock/loop/end生成
Task 2: SocketBox listen()修正(1日)
ファイル: src/boxes/socket_box.rs
pub fn listen(&self, backlog: Box<dyn NyashBox>) -> Box<dyn NyashBox> {
let backlog_num = backlog.to_string_box().value.parse::<i32>().unwrap_or(128);
// 実際にlisten状態を管理
if let Some(ref listener) = *self.listener.lock().unwrap() {
// TcpListenerは既にlisten状態
// 内部状態を更新
*self.status.lock().unwrap() = SocketStatus::Listening;
Box::new(BoolBox::new(true))
} else {
Box::new(BoolBox::new(false))
}
}
Task 3: エラーハンドリング改善(2日)
対象ファイル:
src/boxes/http_server_box.rssrc/boxes/socket_box.rssrc/boxes/http_message_box.rs
変更例:
// Before
let listener = self.listener.lock().unwrap();
// After
let listener = match self.listener.lock() {
Ok(l) => l,
Err(_) => return Box::new(StringBox::new("Error: Failed to acquire lock")),
};
Task 4: HTTPサーバー実用化(2日)
ファイル: src/boxes/http_server_box.rs
- スレッドプール実装
- 適切なシャットダウン
🎯 完了条件
-
WASM/AOT成功
$ ./target/release/nyash --compile-wasm test_wasm_loop.nyash ✅ WASM compilation completed successfully! -
HTTPサーバー実動作
$ ./target/release/nyash test_http_server_real.nyash & $ curl http://localhost:8080/ <h1>Nyash Server Running!</h1> -
エラーハンドリング
- unwrap()使用箇所: 26 → 5以下
📊 性能目標
- WASM実行: 現在11.5倍 → 13.5倍以上
- HTTPサーバー: 100 req/sec以上
🔧 参考資料
🎉 期待される成果
Phase 9.51完了により、Nyashは:
- 実用的なWebアプリケーション開発が可能に
- 高速なAOT実行ファイル配布が実現
- 本番環境での安定動作を保証
Everything is Box哲学を守りながら、実用性を達成します!🐱