Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
7af3067
fix(node): close the advisory-lock probe's session if it is dropped m…
beardthelion Jul 29, 2026
edcf0f2
fix(node): add a dedicated, lazily-connected advisory-lock pool
beardthelion Jul 29, 2026
5ce3c7f
fix(node): hold the lock-owning connection in RepoWriteGuard (#279)
beardthelion Jul 29, 2026
c49d3cd
fix(node): free the advisory lock when a write guard dies without rel…
beardthelion Jul 29, 2026
98f2daf
fix(node): read the advisory unlock's result instead of discarding it
beardthelion Jul 29, 2026
9321d3b
fix(node): bound the object-storage transfers that run under the writ…
beardthelion Jul 29, 2026
9da0939
fix(node): authorize before taking the write lock in close_issue
beardthelion Jul 29, 2026
5d254fb
fix(node): address the review findings on the advisory-lock series
beardthelion Jul 30, 2026
d346bde
fix(node): log lock-pool saturation in the request path, not via read…
beardthelion Jul 30, 2026
82143ad
fix(node): refuse a write when object storage is unknowable, and shed…
beardthelion Jul 30, 2026
8cf6b7a
fix(node): re-authorize close_issue under the guard instead of only r…
beardthelion Jul 30, 2026
af5948b
style(node): rustfmt the new contention test
beardthelion Jul 30, 2026
e5558fb
fix(node): shed an unrefreshable write as a retryable 503 with a fixe…
beardthelion Aug 3, 2026
63a9ef8
fix(node): refuse a fresh-copy write when the archive HEAD cannot be …
beardthelion Aug 3, 2026
10230ac
fix(node): log expected transient acquire failures at warn, not error
beardthelion Aug 3, 2026
259d587
fix(node): log the read failure the close_issue pre-check folds into …
beardthelion Aug 3, 2026
999ee72
test(node): poll for the closed session instead of sleeping a fixed 3…
beardthelion Aug 3, 2026
5fdb902
fix(node): raise a failed fresh download with no local copy as RepoUn…
beardthelion Aug 9, 2026
f81ebbe
test(node): assert the second writer sheds as RepoBusy instead of tim…
beardthelion Aug 9, 2026
c4dbd8a
fix(node): read the close_issue author pre-check from a non-mutating …
beardthelion Aug 10, 2026
9f313b9
fix(node): bound every await in the lock-acquire loop by the deadline
beardthelion Aug 10, 2026
60d70c7
test(node): add an S3 mock that really enforces conditional writes
beardthelion Aug 10, 2026
31f90c4
fix(node): stop pretending a held lock fences a late upload
beardthelion Aug 10, 2026
3eabf79
feat(node): let the storage client express and detect a conditional w…
beardthelion Aug 10, 2026
317841e
fix(node): fence the release publish so an abandoned upload cannot win
beardthelion Aug 10, 2026
3d803ff
test(node): drive the abandoned-upload race end to end, and probe the…
beardthelion Aug 10, 2026
2a92a1f
fix(node): reconcile F-series tests and test seams with the rebased g…
beardthelion Aug 18, 2026
9f35dca
fix(node): address the 2026-08-10 review round on the advisory-lock s…
beardthelion Aug 18, 2026
9dd71e9
fix(node): record why the close-issue read gate cannot carry a synced…
beardthelion Aug 18, 2026
4cee7e0
merge origin/main into fix/279-advisory-lock-session-affinity
beardthelion Aug 26, 2026
b35cb31
fix(node): address jatmn review on merged advisory-lock head
beardthelion Aug 26, 2026
3c20148
fix(node): cap close_issue snapshot work on the read pool
beardthelion Aug 26, 2026
7ba0fef
fix(node): mark close_issue mirror visibility gate for push hook
beardthelion Aug 26, 2026
3df71c9
fix: unblock pre-push after main merge
beardthelion Aug 26, 2026
98fe670
fix(node): carry transient acquire failures through every write handler
beardthelion Aug 28, 2026
4f1c1bb
fix(node): drop unused logcap helper after drain_faults seam
beardthelion Aug 28, 2026
4eb0c44
fix(node): route fork disk paths through validated_repo_disk_path
beardthelion Aug 28, 2026
d1ce2e3
fix(node): harden release-upload outcomes and replication tail gating
beardthelion Aug 28, 2026
8e66e77
fix(node): close jatmn round on publish authority and durability gating
beardthelion Aug 29, 2026
1911291
fix(node): harden issue close/create and fork publish paths on #285
beardthelion Aug 29, 2026
5d3a4ea
fix(node): close write-attempt ownership gaps on advisory-lock release
beardthelion Aug 29, 2026
2ad2f12
fix(node): gate replication tail on publish durability and split clos…
beardthelion Aug 29, 2026
487687c
fix(node): add ValidatedRepoDiskPath for CodeQL and reconcile tail du…
beardthelion Aug 29, 2026
9d02139
fix(node): close three jatmn findings on advisory-lock PR
beardthelion Aug 30, 2026
85c6f48
fix(node): verify adversarial findings on advisory-lock PR
beardthelion Aug 30, 2026
5cd6703
fix(node): compensate under the write lock and harden tail durability…
beardthelion Aug 30, 2026
22da2d6
fix(node): refuse stale under-lock refresh and gate tail durability o…
beardthelion Aug 30, 2026
c306933
style(node): rustfmt advisory-lock gap-closure commits
beardthelion Aug 30, 2026
3a82ccb
fix(node): satisfy clippy on stale-local download test path join
beardthelion Aug 30, 2026
c40f299
feat(node): add a publish attempt/stage boundary
kevincodex1 Aug 31, 2026
21646bc
feat(node): stamp uploads with an attempt id and preserve dispatch am…
kevincodex1 Aug 31, 2026
5e548d2
fix(node): key durability, cache validity and fork cleanup on the att…
kevincodex1 Aug 31, 2026
535c5dc
fix(node): settle the cache contract on the abandoned path and the at…
beardthelion Sep 7, 2026
f048a1e
fix(node): settle the abandoned tree at the disconnect, not at reaper…
beardthelion Sep 7, 2026
957d50b
fix(node): let exactly one classifier settle an abandoned tree
beardthelion Sep 7, 2026
892c752
Merge origin/main into fix/279-advisory-lock-session-affinity
beardthelion Nov 4, 2026
28f3fc2
test(node): use the test's own pool now that Db::pool is gone
beardthelion Nov 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(node): bound every await in the lock-acquire loop by the deadline
The remaining budget was checked before the pool checkout but bounded neither
the checkout nor the pg_try_advisory_lock query that follows it. A checkout
starting just under the deadline could wait out the pool's own acquire timeout,
and a slow query could be accepted after the budget was spent, so the advertised
wall-clock cap held only on the fast path.

Both awaits now run under the remaining budget and shed as RepoBusy when it runs
out. The probe's Drop closes its session, which cannot hold a lock it never
confirmed taking, so the query-timeout arm is a plain shed.
  • Loading branch information
beardthelion committed Aug 18, 2026
commit 9f313b9bf78c3e84f5fee0803dc08b8d84215f0a
123 changes: 114 additions & 9 deletions crates/gitlawb-node/src/git/repo_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,22 @@ impl RepoStore {
let deadline = std::time::Instant::now() + deadline_budget;
let mut lock_conn = None;
for attempt in 0..60 {
let Some(left) = deadline.checked_duration_since(std::time::Instant::now()) else {
break;
// The advertised cap is WALL CLOCK, so the remaining budget must bound
// every await in the loop, not just the sleep between attempts. A pool
// checkout or a slow advisory query that starts just before the deadline
// and lands after it would otherwise hold the write task past the budget
// it was promised, which is exactly what the deadline exists to prevent.
let left = match deadline.checked_duration_since(std::time::Instant::now()) {
Some(left) if !left.is_zero() => left,
_ => break,
};
if left.is_zero() {
break;
}
let conn = match self.lock_pool.acquire().await {
Ok(c) => c,
Err(e) => {
// Bound the pool checkout by the remaining budget. A checkout that
// would outlive the deadline is not worth starting: it either waits out
// the full DB acquire timeout and fails anyway, or lands a connection
// with no budget left to use it.
let conn = match tokio::time::timeout(left, self.lock_pool.acquire()).await {
Ok(Ok(c)) => c,
Ok(Err(e)) => {
// Saturation is surfaced HERE, in the request path, and
// deliberately not through /ready. Failing readiness on a full
// pool would pull this node out of routing, taking its reads
Expand All @@ -378,9 +385,51 @@ impl RepoStore {
);
return Err(e).context("advisory-lock pool exhausted or unreachable");
}
Err(_) => {
// The pool checkout itself outlived the remaining budget. Same
// refusal as running out of attempts: the wall-clock cap is what
// is advertised, so a checkout that blows past it is contention
// the caller was promised would not happen.
warn!(
repo = %repo_name,
owner = %owner_slug,
waited_secs = deadline_budget.as_secs(),
"advisory-lock pool checkout exceeded the acquire deadline — shedding the write as busy"
);
return Err(anyhow::Error::new(RepoBusy).context(format!(
"advisory-lock pool checkout exceeded the {}s deadline for {owner_slug}/{repo_name}",
deadline_budget.as_secs()
)));
}
};
// Bound the advisory query by the remaining budget too: a query that
// starts with budget left but answers after the deadline must not be
// accepted, or the cap is only as good as the fast path.
let left = match deadline.checked_duration_since(std::time::Instant::now()) {
Some(left) if !left.is_zero() => left,
_ => break,
};
let mut probe = LockProbe::new(conn);
if probe.try_lock(lock_key).await? {
let acquired = match tokio::time::timeout(left, probe.try_lock(lock_key)).await {
Ok(Ok(acquired)) => acquired,
Ok(Err(e)) => return Err(e).context("trying advisory lock"),
Err(_) => {
// The query outlived the remaining budget. The probe's Drop
// closes its session, which cannot hold the lock it never
// confirmed taking, so this is a plain shed.
warn!(
repo = %repo_name,
owner = %owner_slug,
waited_secs = deadline_budget.as_secs(),
"advisory-lock query exceeded the acquire deadline — shedding the write as busy"
);
return Err(anyhow::Error::new(RepoBusy).context(format!(
"advisory-lock query exceeded the {}s deadline for {owner_slug}/{repo_name}",
deadline_budget.as_secs()
)));
}
};
if acquired {
lock_conn = probe.take_conn();
break;
}
Expand Down Expand Up @@ -3191,4 +3240,60 @@ mod tests {
server.abort();
}

/// P2: the lock-acquire deadline must bound EVERY await in the retry loop,
/// not just the sleep between attempts. A pool checkout that would exceed
/// the deadline must shed as `RepoBusy` rather than wait out the pool's own
/// acquire timeout past the promised wall-clock cap.
///
/// Observable: hold every lock-pool slot from an independent store, then
/// acquire with a short deadline. The pool checkout will not complete within
/// the deadline, so `acquire_write` must refuse as `RepoBusy` once the
/// deadline fires — not hang for the pool's 5s acquire timeout.
#[sqlx::test]
async fn pool_checkout_past_the_deadline_sheds_as_repo_busy(pool: PgPool) {
let opts = (*pool.connect_options()).clone();

// Exhaust every slot of the lock pool. The checkouts must come from the
// pool the store will use, not from independent connections: a separate
// `PgConnection::connect_with` consumes no slot, so the store's checkout
// would succeed immediately and the deadline would never be reached.
const N: u32 = 2;
let lock_pool = no_reap_pool(&opts, N).await;
let mut holders = Vec::new();
for _ in 0..N {
holders.push(lock_pool.acquire().await.expect("hold a lock-pool slot"));
}

// The store shares that exhausted pool (`PgPool` is a handle to one
// inner pool, so the clone is the same set of slots).
let store =
RepoStore::for_testing(PathBuf::from("/tmp/gitlawb-deadline"), lock_pool.clone())
.with_lock_acquire_deadline(std::time::Duration::from_millis(400));

// The pool is exhausted, so the checkout cannot complete within the
// deadline; the deadline must fire and shed as RepoBusy rather than let
// the pool's own 5s acquire timeout run.
let started = std::time::Instant::now();
let err = match store
.acquire_write("did:key:z6MkDeadline", "deadline-repo")
.await
{
Err(e) => e,
Ok(guard) => {
guard.release(false).await;
panic!("with the pool exhausted, the deadline must shed, not succeed");
}
};
assert!(
err.downcast_ref::<RepoBusy>().is_some(),
"a checkout past the deadline must shed as RepoBusy, got {err:#}"
);
assert!(
started.elapsed() < std::time::Duration::from_secs(5),
"the refusal must come from the deadline, not the pool's own 5s acquire timeout"
);

// Release the holders so the test's pool can be torn down cleanly.
drop(holders);
}
}