Host function callbacks can deadlock when calling back into the sandbox
メンテナーはふだん 6 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 42/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- javascript, rust
- 領域
- backend
調査の方向性
まず、handle_event 内の call_handler とホスト関数ディスパッチを通じて sandbox lock を追跡し、次に src/hyperlight_host/src/sandbox/outb.rs の separate-lock approach と比較します。registerHostFunction と callHandler を使って callback を再現し、PR #55 の executing_flag を確認します。callback がデッドロックを起こさずに sandbox 操作を呼び出せ、報告された再現ケースのカバレッジがあることを完了条件とします。
索引モデルが issue の本文から書いたものです。
説明
Problem
When a host function callback (registered via registerHostFunction or setHostPrintFn) tries to call back into the same sandbox (e.g. callHandler, snapshot, restore, unload), it deadlocks.
This happens because call_handler holds the LoadedJSSandbox mutex for the entire duration of guest execution. Host functions are dispatched via TSFN to the Node.js main thread while that lock is held. If the callback then calls any method that needs the same lock, it waits forever.
Why this doesn't happen in core hyperlight
In hyperlight-dev/hyperlight, the host function registry (Arc<Mutex<FunctionRegistry>>) uses a separate lock from the sandbox. Host functions are dispatched synchronously while the VM is paused — they don't need the sandbox lock at all. See src/hyperlight_host/src/sandbox/outb.rs.
In hyperlight-js, the QuickJS runtime invokes host function closures inside handle_event, which requires &mut self on the sandbox. The NAPI layer wraps this in a single tokio::sync::Mutex, so host function dispatch and sandbox lifecycle share the same lock.
Current workaround
PR #55 adds an executing_flag (AtomicBool) that detects reentrancy at runtime. If a callback tries to acquire the lock while guest code is executing, it returns ERR_REENTRANT instead of deadlocking. This prevents hangs but doesn't allow the operation to succeed.
Suggested fix
Separate host function dispatch from the sandbox lock, similar to how core hyperlight does it. Options:
- Move host function state out of the
&mut selfborrow so callbacks don't need the sandbox lock - Temporarily release the sandbox lock before dispatching to host functions, reacquire after
- Provide a shared FFI/binding helper crate that handles this pattern correctly for any language binding
Reproduction
const loaded = await sandbox.getLoadedSandbox();
proto.registerHostModule('mymod', (mod) => {
mod.registerHostFunction('callback', async () => {
// This deadlocks (or returns ERR_REENTRANT with the fix)
await loaded.callHandler('other_handler', {});
return 'result';
});
});
- 主要言語
- Rust
- スター
- 13
- フォーク
- 5
- 平均マージ
- 6日 6時間
- マージ済み PR(30日)
- 17
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
hyperlight-dev/hyperlight-js のほかの issue
-
lifecycle/needs-review
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
hyperlight-dev/hyperlight-js#81 ·
メンテナーはふだん 6 日以内に返信
-
lifecycle/needs-review
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
hyperlight-dev/hyperlight-js#340 ·
メンテナーはふだん 6 日以内に返信
-
lifecycle/needs-review
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
hyperlight-dev/hyperlight-js#339 ·
メンテナーはふだん 6 日以内に返信
-
lifecycle/needs-review
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
hyperlight-dev/hyperlight-js#338 ·
メンテナーはふだん 6 日以内に返信
-
lifecycle/needs-review
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
hyperlight-dev/hyperlight-js#337 ·
メンテナーはふだん 6 日以内に返信
hyperlight-dev/hyperlight-js の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 4 日以内に返信
-
`future_into_py` loses the original panic message対応中かも @Danipulok が今日担当しました。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
PyO3/pyo3-async-runtimes#91 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 2 日以内に返信