fix(mcp,store): a close stops every call and job that can run long, and says so; an unrecorded refusal never ran
A close waited, unbounded, for a running books.back_up_now (git only Backups::shut could cancel), for a restore, create or adopt (they hold the one lifecycle lock, and at the server's close admin_jobs.wait() waited for them before anything was released), and, through the store lock, for a verification or a package reading every stored file. The bound's T_calls term was not finite. Now a close calls hurry at its start, and the stoppable work looks at it: books.back_up_now and timer-asked backups (git stopped, a stopped run records 'stopped' and no result of its own), books.verify (per journal line and file; a heal of a drifted database is begun only if no stop came before it: stopped half way it would leave the live ledger part replayed), books.export_cpa_package (per stored file). Such a call answers that it was stopped because the books are closing, and its access record says refused: stopped_by_close. On the admin socket restore, adopt, create and open take a JobStop: asked at each phase and file copied, they remove what they wrote and leave the root byte for byte as it was; the renames that put the books in place are the point of no return, after which they finish (two renames and two syncs). A close of any book, and the server's own, raises the flag before it waits for the lifecycle lock. A close whose last backup had to be killed in the owner's folder now says which file was left, and the target's backup is marked failed by shut when the run's future was dropped at its bound. INVARIANT 10 is rewritten so each term of the bound is enforced by code, and lists the calls that can run long (and the one known exception, books.import_bank_csv); INVARIANTS 8 and 9 say exactly which refusals are recorded and why an unrecorded one never ran; the format upgrade's wording says a stop is honoured up to its final look. Tests: the close is held to the bound while a backup call, a verification, a package and each admin job is running and would never end; the stopped job leaves the root byte for byte as it was; a lock left in a backup folder is reported and never removed. Sleeps that stood for 'the other side got there' now wait on the condition (Expect: 100-continue for a half-sent body, a writable named pipe for a fetch that is reading). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6f174f3f87
commit
aa64df9a25
18 files changed
+1889
-248
No files matched your search
@@ -55,7 +55,7 @@
|
||||
//! stopped gently: SIGTERM to its whole process group first (git
|
||||
//! removes the lock files it holds when it is sent one, and a push's
|
||||
//! receiving end the objects it had not yet kept), up to TERM_GRACE
|
||||
//! (3 s: git's handler takes milliseconds, so the grace is only for a
|
||||
//! (5 s: git's handler takes milliseconds, so the grace is only for a
|
||||
//! machine too loaded to schedule it) for the group to end, and only
|
||||
//! then SIGKILL. So a lock left behind is the rare case, and there is
|
||||
//! nothing to clean up in the usual one. (Windows has no signal to
|
||||
@@ -138,9 +138,11 @@ pub const BACKED_UP: [&str; 5] = [
|
||||
pub const GIT_TIMEOUT: Duration = Duration::from_secs(300);
|
||||
/// How long a git that is to be stopped is given, after SIGTERM, to end
|
||||
/// (and so remove its own lock files) before its whole process group is
|
||||
/// killed (INVARIANT 5). Git's handler takes milliseconds; this is for a
|
||||
/// machine so loaded that the handler is slow to be scheduled.
|
||||
pub const TERM_GRACE: Duration = Duration::from_secs(3);
|
||||
/// killed (INVARIANT 5). Git's handler takes milliseconds; the grace is for
|
||||
/// a machine so loaded that the handler is slow to be scheduled. It is
|
||||
/// generous on purpose: a lock left in the owner's folder costs the owner a
|
||||
/// step by hand, while a longer grace costs only a git that ignores SIGTERM.
|
||||
pub const TERM_GRACE: Duration = Duration::from_secs(5);
|
||||
/// How old a lock in the book's own archive must be, at open and when a
|
||||
/// backup begins, before it is taken for a dead git's (INVARIANT 5a): a
|
||||
/// younger one is left, and the next backup tries again.
|
||||
@@ -749,7 +751,10 @@ impl Watched {
|
||||
|
||||
fn open(&self) -> std::io::Result<crate::git_locks::RepoDir> {
|
||||
if self.is_archive() {
|
||||
match (self.dir.parent(), self.dir.file_name().and_then(|n| n.to_str())) {
|
||||
match (
|
||||
self.dir.parent(),
|
||||
self.dir.file_name().and_then(|n| n.to_str()),
|
||||
) {
|
||||
(Some(book), Some(name)) => crate::git_locks::RepoDir::open_in(book, name),
|
||||
_ => Err(std::io::ErrorKind::InvalidInput.into()),
|
||||
}
|
||||
@@ -2937,7 +2942,10 @@ mod tests {
|
||||
assert!(Path::new(path).exists(), "{path}");
|
||||
}
|
||||
let words = said.to_string();
|
||||
assert!(words.contains("nothing else is using the backup folder"), "{words}");
|
||||
assert!(
|
||||
words.contains("nothing else is using the backup folder"),
|
||||
"{words}"
|
||||
);
|
||||
assert!(!words.contains("another.lock"), "{words}");
|
||||
// Left where it was, and the one before our push untouched.
|
||||
assert!(lock.exists(), "a file in the owner's folder was deleted");
|
||||
@@ -2946,15 +2954,17 @@ mod tests {
|
||||
assert!(
|
||||
notes.iter().all(|n| n.repo == "folder"
|
||||
&& !n.removed
|
||||
&& n.path.as_deref()
|
||||
== Some(repo.join(&n.lock).display().to_string().as_str())),
|
||||
&& n.path.as_deref() == Some(repo.join(&n.lock).display().to_string().as_str())),
|
||||
"{notes:?}"
|
||||
);
|
||||
assert!(
|
||||
notes.iter().any(|n| n.lock == "refs/heads/main.lock"),
|
||||
"{notes:?}"
|
||||
);
|
||||
assert!(!notes.iter().any(|n| n.lock.contains("another")), "{notes:?}");
|
||||
assert!(
|
||||
!notes.iter().any(|n| n.lock.contains("another")),
|
||||
"{notes:?}"
|
||||
);
|
||||
// Still there, a later push fails by git's own words, and the file
|
||||
// stays.
|
||||
std::fs::remove_file(hooks.join("slow")).unwrap();
|
||||
|
||||
Reference in new issue
Block a user