fix(rust): Returned::Block deadlocks single-threaded async executors under execute_async
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start with rust/crates/psychoscript/src/host.rs around host::block and the Returned::Block handling described in the issue. Use the minimal #[tokio::test] reproduction and the Runtime::execute_async / Program::run_async entry points to trace where exec::block_on blocks the executor. The work is done when Returned::Block futures are polled asynchronously with the driving executor context, remain cancellable, and the reproduction completes with Ok("done") on a single-threaded Tokio runtime.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Environment
- Crate:
psychoscript0.1.3(dev@f6b504e) - OS/arch: macOS arm64 (
rustc 1.99.1), single-threaded Tokio (#[tokio::test], defaultflavor = "current_thread")
Summary
When driving a program asynchronously via Runtime::execute_async / Program::run_async on a single-threaded async executor (such as #[tokio::test]'s default current_thread runtime), calling a synchronous HostFunction that returns Returned::Block(future) deadlocks the executor until timeout_ms fires (or hangs forever if timeout_ms is None).
Root Cause
host::block (rust/crates/psychoscript/src/host.rs:1048) waits for Returned::Block futures via wait(...) -> exec::block_on(...), which parks the driving executor thread in Condvar::wait:
- Before
OFFLOAD_AFTER(< 1 ms,home_of(vm) == None):blockcallswait(...)directly on the executor thread. - After
OFFLOAD_AFTER(>= 1 ms,home_of(vm) == Some(home)):blockhandswait(...)back to the executor thread viahome.run(...), which still runsexec::block_on(...)on the executor thread insideWorker::poll.
Because the single-threaded executor is parked in Condvar::wait, its timer/I/O reactor (or sibling tasks) can never run to wake the future.
Minimal Reproduction
use std::time::Duration;
use psychoscript::{HostFunction, HostValue, Limits, ProgramOptions, Returned, Runtime};
#[tokio::test] // default current_thread runtime
async fn returned_block_deadlocks_current_thread_tokio() {
let rt = Runtime::make()
.limits(Limits {
timeout_ms: Some(1_000),
..Default::default()
})
.globals(|_| {
let sleep = HostFunction::new(|_, _| {
Returned::Block(Box::pin(async {
tokio::time::sleep(Duration::from_millis(10)).await;
Ok(HostValue::from("done"))
}))
});
[("sleepSync", HostValue::from(sleep))]
});
let out = rt
.execute_async("return sleepSync();", &ProgramOptions::new())
.await
.unwrap();
// Actual: Err(Diagnostic { kind: TimeoutExceeded, message: "Execution timed out after 1000ms." })
// Expected: Ok("done") in ~10ms
assert_eq!(out.json().unwrap(), serde_json::json!("done"));
}
Expected Behavior
In execute_async / run_async, Returned::Block futures should be polled asynchronously with the driving executor's Context (returning Poll::Pending when pending, both before and after offload) so single-threaded executors remain free to drive timers, I/O, and sibling tasks — and dropping the outer future cancels the in-flight Returned::Block future on the executor thread.
- Lenguaje dominante
- Rust
- Estrellas
- 470
- Forks
- 11
- Merge medio
- 4 h 10 min
- PR fusionados (30 d)
- 89
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de anomalyco/psychoscript
-
fix(rust): large BigInts bypass Limits::max_heap_bytesPosiblemente ocupada @brxs la tomó hace 2 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
anomalyco/psychoscript#113 ·
Los mantenedores suelen responder en 1 día
-
fix(rust): duplicate fresh strings bypass Limits::max_heap_bytesPosiblemente ocupada @brxs la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
anomalyco/psychoscript#109 ·
Los mantenedores suelen responder en 1 día
-
Importing psychoscript throws RangeError in Safari (WebKit/JavaScriptCore)Posiblemente ocupada @vibdev la tomó hace 2 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 35/100
anomalyco/psychoscript#100 ·
Los mantenedores suelen responder en 1 día
-
Runs fail with `setImmediate is not defined` in browsers and Convex's runtime once a program runs longer than ~1 msPosiblemente ocupada @fengqiaoqu la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
anomalyco/psychoscript#82 ·
Los mantenedores suelen responder en 1 día
Todos los issues de anomalyco/psychoscript
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Top-right curve point in Color Grading cannot be dragged on macOS (scrollbar intercepts click)Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
storytold/filmcraft#5386 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
enhancement in-progress
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100