q2 preview: a re-execute still writing its capture to samod blocks runtime shutdown forever
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 22/100
Direzione di ricerca
Start with crates/quarto-preview/src/re_execute.rs, where perform_re_execute runs on spawn_blocking and calls samod's Repo::create, then read the flaky test live_reexecute::auto_re_runs_after_a_stale_copy_was_served_at_startup in crates/quarto-preview/tests/integration/live_reexecute.rs. Reproduce with the diagnostic test from the issue, then move the samod write onto the runtime so shutdown drops it. Done when the hang no longer occurs and the tests wait for the worker and check the final sidecar.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
A re-execute worker that is still writing its capture to samod when the tokio runtime shuts down never returns, and the runtime's shutdown waits for it forever. This is what hangs live_reexecute::auto_re_runs_after_a_stale_copy_was_served_at_startup on macOS until the job is cancelled, on main in https://github.com/quarto-dev/q2/actions/runs/45260078239/job/137992188063 and in https://github.com/quarto-dev/q2/actions/runs/45432297037/job/138580999778 (still SLOW after more than 18,000 s).
The worker runs perform_re_execute with pollster::block_on on a spawn_blocking thread:
and stores the capture through samod's Repo::create:
In samod 0.16, create waits on a oneshot whose sender is kept in the repo's own pending_commands. The io loop task resolves it once the document is persisted (source):
pub async fn create(&self, initial_content: Automerge) -> Result<DocHandle, Stopped> {
let (tx, rx) = oneshot::channel();
{
let DispatchedCommand { command_id, event } =
HubEvent::create_document(initial_content);
let mut inner = self.inner.lock().unwrap();
inner.handle_event(event);
inner.pending_commands.insert(command_id, tx);
drop(inner);
}
let inner = self.inner.clone();
match rx.await {
// ...
Err(_) => Err(Stopped),
}
}
When the runtime shuts down, the io loop task is dropped, but the sender is not: the worker's own context clone keeps the repo alive. rx.await never resolves, so the blocking thread never exits, and Runtime::drop waits on the blocking pool forever.
How the test gets there
The test returns as soon as the engine has run twice and the .quarto copy holds three:
The engine stage writes that copy before the run publishes its capture, so the test often returns while the worker is still running. With temporary logging, 23 of 40 local runs on Windows returned with the worker still in flight, 21 of them before the sidecar was updated. The test still passed 40 of 40 times: samod's write usually completes about 1 ms before the shutdown drops the io loop. On macOS CI it lost that race.
I can reproduce the hang deterministically on Windows. A test that returns while the worker is held in the stub engine, with the gate opened 500 ms later from another thread, logs the start of the samod write and never its end. nextest has to kill it.
Experiment (not meant to land)
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn return_while_a_worker_runs() {
let dir = tempfile::TempDir::with_prefix("q2-live-diag-").unwrap();
let root = dir.path().canonicalize().unwrap();
let doc = root.join("doc.qmd");
std::fs::write(&doc, recording_doc("ok1")).unwrap();
let probe = Probe::default();
let reg = registry(&probe);
let c = cfg(EnginePolicy::Auto, &root.join("cache"), vec![RecordSource::Engine]);
let (ctx, _data) = hub_ctx(&root).await;
capture_driver::record_eager_captures(ctx.clone(), plain_runtime(), Some(reg.clone()), &c)
.await
.unwrap();
std::fs::write(&doc, recording_doc("BLOCK")).unwrap();
capture_driver::recompute_staleness(ctx.clone(), plain_runtime(), "doc.qmd", Some(reg), &c)
.await
.unwrap();
wait_for("the blocked run to start", 30, || runs(&probe) == 2).await;
let gate = probe.gate.clone();
std::thread::spawn(move || {
std::thread::sleep(Duration::from_millis(500));
gate.release();
});
std::mem::forget(dir);
}
worker: start
perform: compute_source_inputs done
test: body RETURNS
diag: releasing the gate (runtime is tearing down)
perform: engine run done (copy written)
perform: store_run done
perform: write_capture_doc_gated (samod create) BEGIN
SLOW [> 30.000s] live_reexecute::zz_diag_return_while_a_worker_runs
SLOW [> 60.000s] live_reexecute::zz_diag_return_while_a_worker_runs
TERMINATING [> 90.000s] live_reexecute::zz_diag_return_while_a_worker_runs
In q2 preview
q2 preview drops its runtime after block_on(run(args)) returns:
So I think a Ctrl-C during an auto re-execute could hang the exit the same way. I haven't verified this end to end.
Possible fix
We could run the worker as a tokio task and keep only the engine part (source inputs, engine run, cache store) on spawn_blocking. The samod write, the sidecar update and the end-of-run re-check would then run on the runtime, and a shutdown drops them instead of waiting on them. Separately, the tests could wait for the worker to finish and check the final sidecar state, not only the .quarto copy.
The tests were added in #1196. #1200 is an earlier samod lifecycle fix (flushing storage before dropping the hub context), for a different test. The Ubuntu timeout of the sibling test in the same file has a separate cause, filed as #1340.
- Lingua principale
- Rust
- Stelle
- 316
- Fork
- 23
- Merge medio
- 11h 49m
- PR unite (30g)
- 245
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di quarto-dev/q2
-
Heading anchor links have no icon: AnchorJS is initialised with an empty `icon`Forse già presa @cscheid l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
quarto-dev/q2#1419 ·
I maintainer di solito rispondono entro 1 giorno
-
bug testing windows
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
quarto-dev/q2#1346 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
quarto-dev/q2#1095 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
quarto-dev/q2#1418 ·
I maintainer di solito rispondono entro 1 giorno
-
bug readers-writers windows
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
quarto-dev/q2#1416 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di quarto-dev/q2
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 82/100
BurntSushi/jiff#755 ·
I maintainer di solito rispondono entro 1 giorno
-
After the kernel is given up on, a new import leaves "Importing…" and its Cancel on the status lineApertabug help wanted priority: low
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
sawhorse3d/sawhorse#163 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
MartinPTielemans/ilo#4607 ·