From 8ae063d38762d7e7e88ec4411436d7605d8b767c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 12 Sep 2026 21:09:12 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20replay=20re-check=20on=20?= =?UTF-8?q?the=20zero-seat=20path=20(same-student=20race)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...00e9a08f3e2cdb91cc6fddd14e506e05e0ed6.json | 24 +++++++++++++++++++ src/db/meal_booking.rs | 16 +++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 .sqlx/query-d64689d8966396fe6d88d2a9d4000e9a08f3e2cdb91cc6fddd14e506e05e0ed6.json diff --git a/.sqlx/query-d64689d8966396fe6d88d2a9d4000e9a08f3e2cdb91cc6fddd14e506e05e0ed6.json b/.sqlx/query-d64689d8966396fe6d88d2a9d4000e9a08f3e2cdb91cc6fddd14e506e05e0ed6.json new file mode 100644 index 0000000..336985a --- /dev/null +++ b/.sqlx/query-d64689d8966396fe6d88d2a9d4000e9a08f3e2cdb91cc6fddd14e506e05e0ed6.json @@ -0,0 +1,24 @@ +{ + "db_name": "PostgreSQL", + "query": "SELECT 1 AS held FROM meal_booking\n WHERE menu = $1 AND student = $2 AND status = 'booked'", + "describe": { + "columns": [ + { + "ordinal": 0, + "name": "held", + "type_info": "Int4", + "origin": "Expression" + } + ], + "parameters": { + "Left": [ + "Text", + "Uuid" + ] + }, + "nullable": [ + null + ] + }, + "hash": "d64689d8966396fe6d88d2a9d4000e9a08f3e2cdb91cc6fddd14e506e05e0ed6" +} diff --git a/src/db/meal_booking.rs b/src/db/meal_booking.rs index 1c74c23..661157a 100644 --- a/src/db/meal_booking.rs +++ b/src/db/meal_booking.rs @@ -185,6 +185,22 @@ pub(crate) async fn claim_and_place( .fetch_optional(&mut *tx) .await?; if seat.is_none() { + // A racer whose held-check ran before the winner's row landed and + // then queued on the menu row lock wakes to a full menu with its + // own booking already placed — that is the replay, not a refusal. + // (Each statement sees a fresh committed snapshot, so this read + // observes the winner's row.) + let won_elsewhere = sqlx::query!( + "SELECT 1 AS held FROM meal_booking + WHERE menu = $1 AND student = $2 AND status = 'booked'", + menu_key, + student, + ) + .fetch_optional(&mut *tx) + .await?; + if won_elsewhere.is_some() { + return Ok(Claimed::Duplicate); + } return Ok(Claimed::Full); } // Revive a cancelled row only while it still stands at the attempt