From 340ff4f1cc3848717c9a34a58235686322a26410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 5 Aug 2026 03:43:10 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=93=9A=20hold=20the=20exam=20lease?= =?UTF-8?q?=20while=20a=20course=20cascade=20sweeps=20sittings?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit delete_course takes the same cascade delete_exam does — its courses' exams and their attempts — and had the same hole: an attempt is the one exam child whose write cannot collide with the sweep, because its claim lands on the student's row rather than the exam's. Narrower than the exam twin, since the delete is refused while anyone is enrolled: a start would have to pass its enrollment gate and then have that enrollment removed under it. Same hole, same lease. Nothing on this path takes another lock, so it adds no ordering pair. No test of its own — the window needs an unenroll landing inside a start's own lease, which no sequence of HTTP calls can arrange. The mechanism is the one regress_exam_delete already pins. --- src/web/courses.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/web/courses.rs b/src/web/courses.rs index 62ddade..cc25658 100644 --- a/src/web/courses.rs +++ b/src/web/courses.rs @@ -525,6 +525,15 @@ async fn delete_course( "only the course creator or a manager/admin can delete this course", )); } + // Writer lease of [`EXAM_LOCK`], for `delete_exam`'s reason: this cascade + // sweeps the course's exams *and their attempts*, and an attempt is the one + // exam child whose write cannot collide with the sweep (its claim lands on + // the student's row, never the exam's). Narrower here — the delete is + // refused while anyone is enrolled, so a start would have to pass its + // enrollment gate and then have that enrollment removed under it — but the + // hole is the same one and so is the lease. Nothing on this path takes + // another lock, so it introduces no ordering pair. + let _guard = crate::web::exams::EXAM_LOCK.write().await; // Rows go first (the delete cascades them), blobs after — a crash in // between strands at worst an unreachable blob. The keys are read before // the delete because it takes their rows with it; a refused delete just