Host function callbacks can deadlock when calling back into the sandbox
维护者通常 6 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 42/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- javascript, rust
- 领域
- backend
调研方向
首先跟踪 handle_event 中经由 call_handler 和 host-function dispatch 的 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 小时
- 30 天内合并 PR
- 17
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 一周以上 新手友好度 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
-
[Misdetection] `text/tab-separated-values` file misdetected as `text/tsv`可能已有人在做 @bact 今天认领。 未关闭misdetection needs triage
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
C-bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
vxc prints a debug line '[flat-codegen] emitted module via the flat path' on every compile可能已有人在做 @YodHeVauHe 今天认领。 未关闭devex good first issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复