📚 hold the exam lease while a course cascade sweeps sittings
Browse files at this commit340ff4f1cc3848717c9a34a58235686322a26410Parent: 00207fe- fix
- 📚 hold the exam lease while a course cascade sweeps sittings
1 changed file +9 -0
- src/web/courses.rs +9 -0
src/web/courses.rsmodified+9 -0
| @@ -525,6 +525,15 @@ async fn delete_course( | |||
| 525 | "only the course creator or a manager/admin can delete this course", | 525 | "only the course creator or a manager/admin can delete this course", |
| 526 | )); | 526 | )); |
| 527 | } | 527 | } |
| 528 | + // Writer lease of [`EXAM_LOCK`], for `delete_exam`'s reason: this cascade | ||
| 529 | + // sweeps the course's exams *and their attempts*, and an attempt is the one | ||
| 530 | + // exam child whose write cannot collide with the sweep (its claim lands on | ||
| 531 | + // the student's row, never the exam's). Narrower here — the delete is | ||
| 532 | + // refused while anyone is enrolled, so a start would have to pass its | ||
| 533 | + // enrollment gate and then have that enrollment removed under it — but the | ||
| 534 | + // hole is the same one and so is the lease. Nothing on this path takes | ||
| 535 | + // another lock, so it introduces no ordering pair. | ||
| 536 | + let _guard = crate::web::exams::EXAM_LOCK.write().await; | ||
| 528 | // Rows go first (the delete cascades them), blobs after — a crash in | 537 | // Rows go first (the delete cascades them), blobs after — a crash in |
| 529 | // between strands at worst an unreachable blob. The keys are read before | 538 | // between strands at worst an unreachable blob. The keys are read before |
| 530 | // the delete because it takes their rows with it; a refused delete just | 539 | // the delete because it takes their rows with it; a refused delete just |