Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
34df1fd
feat(node): add per-IP write-surface rate brake and apply to write_ro…
beardthelion Jul 13, 2026
74e05be
feat(node): extend the per-IP write brake to the remaining write sinks
beardthelion Jul 13, 2026
6fded6e
test(node): adversarial TrustedProxy verification through the write b…
beardthelion Jul 13, 2026
e6324d2
feat(node): purge-spam admin subcommand for the empty-burst cleanup
beardthelion Jul 13, 2026
285d7c7
fix(review): make purge-spam empty-check reject git-discovery reads
beardthelion Jul 13, 2026
090019d
fix(review): normalization-consistent purge, brake helper, CLI + cove…
beardthelion Jul 13, 2026
dfd4f6c
test(review): close the reasoned-not-run gaps by execution
beardthelion Jul 13, 2026
0135419
fix(node): reject path-traversal repo names in purge-spam before remo…
beardthelion Jul 15, 2026
a0fcbb0
fix(node): delete child rows transactionally in delete_repo_by_id
beardthelion Jul 15, 2026
fde9cfe
fix(node): reap write_rate_limiter in the periodic cleanup loop
beardthelion Jul 15, 2026
15522d5
fix(node): hold the per-repo advisory lock across purge recheck+delete
beardthelion Jul 15, 2026
1fcca0d
fix(node): count purge-spam disk-removal failures separately from del…
beardthelion Jul 15, 2026
d9eebd2
fix(node): warn on unparseable rate-limit env vars instead of silentl…
beardthelion Jul 15, 2026
6325402
docs(node): document GITLAWB_IPFS_API/TIGRIS_BUCKET/METRICS_ADDR/SHUT…
beardthelion Jul 15, 2026
bfbe502
test(node): exercise the dry-run guard with a real on-disk candidate …
beardthelion Jul 15, 2026
cdb102e
style(node): cargo fmt for the #196 fix set
beardthelion Jul 15, 2026
4df79f2
fix(node): pin the writer's advisory-lock connection in RepoWriteGuard
beardthelion Jul 15, 2026
68c1f5c
refactor(node): introduce ObjectStore trait seam over TigrisClient
beardthelion Jul 15, 2026
3c1ceb8
fix(node): make purge-spam Tigris-authoritative and archive-deleting
beardthelion Jul 15, 2026
cf669bb
fix(review): don't hold/leak the pool connection in acquire_write
beardthelion Jul 15, 2026
dde5ea9
fix(node): make advisory-lock guards drop-safe and reorder acquire_write
beardthelion Jul 16, 2026
b94d440
fix(node): complete a fully-received push after client disconnect
beardthelion Jul 16, 2026
e4c4161
fix(node): serialize archive uploads under the per-repo advisory lock
beardthelion Jul 16, 2026
6ba698c
fix(node): let purge-spam reach repos that exist only as archives
beardthelion Jul 16, 2026
9f7757c
refactor(node): dedup limiter setup + write-brake test driver; fix .e…
beardthelion Jul 16, 2026
2a78524
docs(node): drop the .env.example shutdown-grace entry #196 added (#196)
beardthelion Jul 19, 2026
c4b337b
fix(node): give advisory-lock guards a dedicated pool and bound the r…
beardthelion Jul 19, 2026
4934646
fix(node): advertise a window-derived Retry-After on rate-limit 429s …
beardthelion Jul 19, 2026
0c279c9
fix(node): skip slug-scoped purge cascade when a mirror row shares th…
beardthelion Jul 19, 2026
86a8228
fix(node): fail closed classifying the purge target directory (#196)
beardthelion Jul 20, 2026
bf2a54e
fix(node): run the push completion tail in the disconnect-surviving t…
beardthelion Jul 20, 2026
c24b541
fix(node): tombstone bounties when their repo is purged (#196)
beardthelion Jul 20, 2026
3baa9ed
fix(node): serialize create_repo against the purge advisory lock (#196)
beardthelion Jul 20, 2026
9916bca
test(node): prove purge deletes at MAX_CONNECTIONS=1 with the split p…
beardthelion Jul 20, 2026
8f3d643
fix(node): fail the push when the durable upload times out, don't 200…
beardthelion Jul 20, 2026
d1e596e
fix(node): tombstone bounties under both owner forms on purge (#196)
beardthelion Jul 20, 2026
ce5dcc3
fix(node): fail closed on a symlink at the purge target (#196)
beardthelion Jul 20, 2026
7dc7be2
fix(node): retry-after on the push-advert 429, and create_repo locks …
beardthelion Jul 20, 2026
d2ba14e
fix(node): correct the create-pool and bounty-tombstone remediations …
beardthelion Jul 20, 2026
5a46ef6
fix(node): close the durable-upload data-loss class on every write pa…
beardthelion Jul 20, 2026
2fa9fa3
chore: merge main (iCaptcha PoW + gl retry tests) into feat/write-sin…
beardthelion Jul 21, 2026
16517f8
refactor(node): route the per-DID 429 through the shared too_many_req…
beardthelion Jul 21, 2026
ba572b3
fix(node): init's background upload waits out the creator's advisory …
beardthelion Jul 21, 2026
859240b
fix(node): roll back the local issue ref before unlock when the durab…
beardthelion Jul 21, 2026
c07435d
fix(node): fork publishes only after a durable upload, serialized on …
beardthelion Jul 21, 2026
2ad1c79
fix(node): read-path downloads publish under the purge lock, without …
beardthelion Jul 21, 2026
b2ca5a7
fix(node): bound every under-lock object-store call and dedup the upl…
beardthelion Jul 21, 2026
fa4322c
fix(node): harden the read-path download against cancellation, stale …
beardthelion Jul 21, 2026
c3d6e73
fix(node): keep the fork's unbounded work out of the target-lock span…
beardthelion Jul 21, 2026
03ef9b5
refactor(node): move read-path download coordination into a repo_stor…
beardthelion Jul 21, 2026
4408d27
fix(node): bound acquire_write's download and free the download-map e…
beardthelion Jul 21, 2026
a12f21a
fix(node): roll back the fork mirror and archive on late clone/insert…
beardthelion Jul 21, 2026
556aa31
fix(node): serialize repo purge cascade with mirror ingest via adviso…
beardthelion Jul 22, 2026
1d8c281
fix(node): roll back local ref on failed durable upload (close/merge/…
beardthelion Jul 22, 2026
1d0d3d2
fix(node): tie cancelled cold-download cleanup to blocking extraction
beardthelion Jul 22, 2026
03cd81e
chore(node): fmt + clippy cleanup for the #196 fixes
beardthelion Jul 22, 2026
9152178
fix(node): never let a failed ref snapshot become a delete-all rollba…
beardthelion Jul 22, 2026
296704f
fix(node): slug-lock every peer-ingest writer and drive the real inge…
beardthelion Jul 22, 2026
1e79ae5
fix(node): own cold-download cleanup in a spawned task so handler can…
beardthelion Jul 22, 2026
ce25bba
refactor(node): delegate issue ref helpers to the store ref primitives
beardthelion Jul 22, 2026
4329b2a
Merge origin/main into feat/write-sink-brake-coverage (reintegrate cu…
beardthelion Jul 22, 2026
d755180
fix(node): slug-lock arweave anchor writes; fail closed when the pre-…
beardthelion Jul 22, 2026
e6f4b2f
fix(node): close review residuals: coalesce cold downloads to one in-…
beardthelion Jul 22, 2026
1459cf2
Merge remote-tracking branch 'origin/main' into feat/write-sink-brake…
beardthelion Nov 11, 2026
da876e8
fix(node): re-apply create/fork purge serialization and restore brake…
beardthelion Nov 11, 2026
edfa6bb
fix(node): close review gaps in purge, locks, and fork cleanup
beardthelion Nov 11, 2026
96ed2b2
fix(node): subscriptions-only ws schema and unsettled-work purge guard
beardthelion Nov 11, 2026
082a37f
Merge remote-tracking branch 'origin/main' into feat/write-sink-brake…
beardthelion Nov 11, 2026
e9e86a1
fix(node): wire close_issue rollback, close purge symlink gap, correc…
beardthelion Nov 11, 2026
1187dca
fix(node): close purge/upload lifecycle gaps from review
beardthelion Nov 11, 2026
261f7ab
fix(node): merge rollback, honest create rollback, purge row recheck
beardthelion Nov 12, 2026
662b9a3
fix(node): probe purge slug liveness, gate issue write brake behind t…
beardthelion Nov 12, 2026
43d4f59
fix(node): close-issue rollback uses resolved ref, drop router brake …
beardthelion Nov 12, 2026
4b483a3
fix(node): close_issue spends neither bucket when either cap refuses,…
beardthelion Nov 12, 2026
11cadb9
fix(node): refund the write slot when the close cap refuses, send Ret…
beardthelion Nov 12, 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): own cold-download cleanup in a spawned task so handler can…
…cellation cannot resurrect temp dirs
  • Loading branch information
beardthelion committed Jul 22, 2026
commit 1e79ae59a554d43fde392e655302a0a1cf758ae8
68 changes: 65 additions & 3 deletions crates/gitlawb-node/src/git/repo_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2734,9 +2734,9 @@ mod tests {
// spawn_blocking extraction resurrect the abandoned temp dir after cleanup.
// The store's extraction lands well past the download timeout; the timeout
// fires, acquire bails, and the extraction then creates ("renames into place")
// temp.path(). The fix ties cleanup to the extraction's completion — a
// detached janitor awaits the download future to settle, then removes the temp
// dir — so no `.tmp-download.*` dir survives. Pre-fix the timeout arm drops the
// temp.path(). The fix ties cleanup to the extraction's completion: a spawned
// task owns the download and the temp guard, so the temp dir is removed only
// once the download settles, and no `.tmp-download.*` dir survives. Pre-fix the timeout arm drops the
// download future, the detached extraction recreates temp.path() AFTER the RAII
// guard's Drop, and it survives forever — the second poll never sees a clean
// parent -> RED.
Expand Down Expand Up @@ -2787,4 +2787,66 @@ mod tests {
"a timed-out cold read must not leave a resurrected .tmp-download.* dir"
);
}

// Cancellation twin of the resurrection test above: the handler future is
// DROPPED mid-download (axum cancels it on client disconnect) instead of
// timing out. Pre-fix, dropping the handler dropped the download future
// while its spawn_blocking extraction kept running; TempDownloadDir::Drop
// removed the (not yet created) temp dir, and the extraction's later
// "rename into place" resurrected it as an orphan that only a later
// same-repo download would sweep -> the cleanup poll never succeeds -> RED.
// Post-fix the spawned task owns the download and the temp guard, keeps
// running across the caller's cancellation, and removes the temp dir once
// the download settles -> GREEN.
#[sqlx::test]
async fn cancelled_cold_read_does_not_resurrect_temp_dir(pool: sqlx::PgPool) {
use std::sync::atomic::Ordering::SeqCst;
let tmp = tempfile::TempDir::new().unwrap();
let extracted = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
let downloads = std::sync::Arc::new(std::sync::atomic::AtomicUsize::new(0));
let ts = DetachExtractStore {
// Long enough that the abort below lands while the extraction is
// still running, so the cancellation drops the download mid-flight.
extract_delay: std::time::Duration::from_millis(600),
downloads: downloads.clone(),
extracted: extracted.clone(),
};
let store = RepoStore::new(
tmp.path().to_path_buf(),
Some(std::sync::Arc::new(ts)),
pool,
);
let owner = "did:key:z6MkCancelResurrectTempDirAAAAAAAAAAAAAAAA";
let name = "cancelresurrect";
let dir = repo_dir_of(tmp.path(), owner, name);
let parent = dir.parent().unwrap().to_path_buf();

// Cold cache miss: the handler enters the download path and its store
// download (the slow extraction) is in flight.
let store2 = store.clone();
let (o2, n2) = (owner.to_string(), name.to_string());
let h = tokio::spawn(async move { store2.acquire(&o2, &n2).await });
assert!(
poll_until_true(|| downloads.load(SeqCst) >= 1).await,
"the reader's download must be in flight"
);

// Drop the handler future mid-download (the client-disconnect hazard).
h.abort();

// Wait for the underlying extraction to settle (the resurrection moment
// pre-fix; the cleanup moment post-fix).
assert!(
poll_until_true(|| extracted.load(SeqCst) >= 1).await,
"the detached extraction must run to completion"
);

// Once the download has settled, no temp dir may survive under the
// parent. Pre-fix the resurrected dir survives and this poll never
// sees a clean parent -> RED.
assert!(
poll_until_true(|| !has_leftover_temp(&parent)).await,
"a cancelled cold read must not leave a resurrected .tmp-download.* dir"
);
}
}
81 changes: 40 additions & 41 deletions crates/gitlawb-node/src/git/repo_store/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ impl RepoStore {
.to_string_lossy();

// Best-effort sweep of leftover temp siblings from a prior download whose
// RAII guard dropped, or whose extract spawn_blocking completed
// uninterruptibly AFTER that guard's Drop ran (finding 1). Serialized per
// cleanup never ran (a process crash or kill mid-download, where no Drop
// and no owning task survive to remove the temp). Serialized per
// repo by the download mutex, so no concurrent same-repo download owns a
// live temp here; scoped to THIS repo's prefix, so other repos are
// untouched.
Expand Down Expand Up @@ -228,56 +228,55 @@ impl RepoStore {
uuid::Uuid::new_v4()
)));

// Bound the network download: a stalled GET would park this reader (and,
// via the per-repo download mutex, every coalesced reader) indefinitely.
// A timeout takes the SAME cleanup arm as a download error (return Err,
// the temp guard's Drop removes the dir), so `download_published` frees
// the map entry and wakes waiters rather than leaving them parked forever.
//
// The download future is OWNED (Box::pin) rather than borrowed so the
// timeout arm can hand the still-running extraction to a detached janitor
// instead of dropping it (finding F3). `store.download` runs its tar
// extraction in `spawn_blocking`, and a tokio timeout does NOT cancel a
// spawn_blocking task: dropping the download future on timeout detaches
// that task, which then renames its extraction into `temp.path()` AFTER
// this function's `temp` guard Drop has already removed the dir —
// resurrecting an abandoned, fully-populated temp dir that the per-repo
// sweep above only reclaims on a later download of the SAME repo, so an
// abandoned extraction for a repo never re-downloaded accumulates on disk.
// Ownership of the download AND the temp-dir guard moves into a spawned
// task, so timeout and handler cancellation share ONE cleanup path
// (finding F3 and its cancellation twin). `store.download` runs its tar
// extraction in `spawn_blocking`, and neither a tokio timeout nor a
// dropped handler future cancels a spawn_blocking task: pre-fix,
// dropping the download future (a timed-out await, or axum dropping the
// whole handler on client disconnect) detached the extraction, whose
// later rename resurrected `temp.path()` AFTER the guard's Drop had
// removed it, leaving an orphan only a later same-repo download sweeps.
// The spawned task is never dropped mid-flight, so the download future
// always runs to settle. On success it returns the still-armed guard
// through the JoinHandle: the caller consumes it and publishes below.
// If the caller timed out or was cancelled, the JoinHandle is gone, so
// the runtime drops the returned guard when the task settles and its
// Drop removes the temp dir; cleanup is tied to the extraction's
// completion, never racing it (this subsumes the previous detached
// janitor). A download error drops the guard inside the task with the
// same at-settle timing.
let store_dl = Arc::clone(store);
let (dl_owner, dl_repo, dl_target) = (
owner_slug.to_string(),
repo_name.to_string(),
temp.path().to_path_buf(),
);
let mut download_fut =
Box::pin(async move { store_dl.download(&dl_owner, &dl_repo, &dl_target).await });
match tokio::time::timeout(self.release_upload_timeout, &mut download_fut).await {
Ok(Ok(())) => {}
Ok(Err(e)) => return Err(e),
let dl_task = tokio::spawn(async move {
match store_dl.download(&dl_owner, &dl_repo, &dl_target).await {
Ok(()) => Ok(temp),
// `temp` drops here: the download settled, so removal is safe.
Err(e) => Err(e),
}
});
// Bound the wait, not the work: a stalled GET would park this reader
// (and, via the per-repo download mutex, every coalesced reader)
// indefinitely. On timeout the caller gets the same error as before and
// `download_published` frees the map entry and wakes waiters; the task
// keeps running and cleans up when the download settles (see above).
let temp = match tokio::time::timeout(self.release_upload_timeout, dl_task).await {
Ok(Ok(Ok(temp))) => temp,
Ok(Ok(Err(e))) => return Err(e),
// The task panicked; its unwind dropped the guard, removing the dir.
Ok(Err(join_err)) => {
return Err(anyhow::Error::from(join_err).context("read download task failed"))
}
Err(_) => {
warn!(repo = %repo_name, timeout_secs = self.release_upload_timeout.as_secs(),
"read download timed out — discarding");
// Do NOT drop the download future here: its spawn_blocking
// extraction may still be running, and dropping detaches it,
// letting its rename resurrect `temp.path()` after cleanup. Tie
// cleanup to the extraction's completion instead — disarm the RAII
// guard and hand the future to a detached janitor that awaits it
// to settle (the spawn_blocking join resolves, so any rename has
// landed) and only THEN removes the temp dir. Waiters are freed
// immediately by the return below; the janitor runs off the
// critical path, bounded by the extraction itself.
let temp_path = temp.path().to_path_buf();
temp.disarm();
tokio::spawn(async move {
let _ = download_fut.await;
let _ =
tokio::task::spawn_blocking(move || std::fs::remove_dir_all(&temp_path))
.await;
});
return Err(anyhow::anyhow!("read download timed out"));
}
}
};

let guard = match self.try_lock_repo(owner_did, repo_name).await {
Ok(Some(g)) => g,
Expand Down