fix(store,mcp): a type claims only what it does alone, and a restore never says 'no such books'
ledger-store: a file coming in (Uploads::receive) now writes each chunk under the lock a close takes and stops at the first chunk after a close, removing its part; an export fetch (Exports::get) reads under that lock, so a close waits for it. The INVARIANTS say exactly this: after close() returns no byte is written or kept and none is read for a caller; the one thing a request begun before the close does after it is remove the part file only it made; a request still waiting for its next bytes is not woken by the type (the books server's gate waits for it and cuts one that never finishes). ledger-mcp: a restore over an open book took the book out of the list before it shut the door, so every call while the restore waited for what was inside got 404 'no such books' for a book that exists. The door is shut first and the book listed closed: such a call gets the closed refusal (503, the words), as in a close. The drain test now requires 503 throughout. (A refusal at a shut door is not written to the access log, as in a close: INVARIANT 11.) Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ce636adbb5
commit
ca6f5aa982
6 files changed
+211
-21
No files matched your search
@@ -1592,27 +1592,42 @@ fn a_restore_over_an_open_book_waits_for_what_is_inside_it() {
|
||||
.unwrap()
|
||||
}
|
||||
});
|
||||
// The books being replaced are no longer served as these.
|
||||
// A call for the books being replaced is told they aren't open (503,
|
||||
// the words, the closed header), as in a close; never that there are
|
||||
// no such books (404), which they would be told if they were taken
|
||||
// out of the list while the restore waits (INVARIANT 10).
|
||||
let late_call = || {
|
||||
let mut late = Wire::with_token(&home, A, Some(w.token().unwrap().to_string()));
|
||||
late.send(&json!({"jsonrpc": "2.0", "id": 1, "method": "ping"}));
|
||||
late.refused.clone().map(|r| (r.status, r.body))
|
||||
};
|
||||
wait_for(
|
||||
"the replaced books are let go",
|
||||
Duration::from_secs(30),
|
||||
|| {
|
||||
let mut late = Wire::with_token(&home, A, Some(w.token().unwrap().to_string()));
|
||||
late.send(&json!({"jsonrpc": "2.0", "id": 1, "method": "ping"}));
|
||||
late.refused
|
||||
.as_ref()
|
||||
.is_some_and(|r| r.status == 404 || r.status == 503)
|
||||
|| match late_call() {
|
||||
Some((404, body)) => panic!("books being restored were `no such books`: {body}"),
|
||||
Some((503, body)) => {
|
||||
assert_eq!(body, closed_words(A));
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
);
|
||||
// The restore (a clone and a check of the backup, which take a second
|
||||
// or so) is not answered while the upload is half received: watched
|
||||
// for five seconds, in which a restore that doesn't wait would finish.
|
||||
// Every call meanwhile gets the same answer.
|
||||
let watched = std::time::Instant::now() + Duration::from_secs(5);
|
||||
while std::time::Instant::now() < watched {
|
||||
assert!(
|
||||
!restoring.is_finished(),
|
||||
"the restore was answered with an upload half received"
|
||||
);
|
||||
assert_eq!(
|
||||
late_call(),
|
||||
Some((503, closed_words(A))),
|
||||
"a call while the books were being restored"
|
||||
);
|
||||
std::thread::sleep(Duration::from_millis(20));
|
||||
}
|
||||
raw.finish(&bytes[bytes.len() / 2..]);
|
||||
|
||||
Reference in new issue
Block a user