Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Host function callbacks can deadlock when calling back into the sandbox

Ouverte
#192 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 5 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
42/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Calme
Stack technique
javascript, rust
Domaine
backend

Piste de recherche

Commencez par suivre le verrou du sandbox à travers call_handler et la distribution des host-functions dans handle_event, puis comparez l’approche avec verrou séparé dans src/hyperlight_host/src/sandbox/outb.rs. Reproduisez le callback à l’aide de registerHostFunction et callHandler, et examinez l’executing_flag de PR #55. Le travail est terminé lorsque les callbacks peuvent appeler des opérations du sandbox sans provoquer de deadlock, avec une couverture pour la reproduction signalée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug lifecycle/needs-review

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:

  1. Move host function state out of the &mut self borrow so callbacks don't need the sandbox lock
  2. Temporarily release the sandbox lock before dispatching to host functions, reacquire after
  3. 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';
  });
});
Langage dominant
Rust
Étoiles
13
Forks
5
Merge moyen
5 j 12 h
PR mergées (30 j)
16

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de hyperlight-dev/hyperlight-js

Toutes les issues de hyperlight-dev/hyperlight-js

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.