Fix the R1 merge: close the Rust store_header visitor; a whole-store replace through a dangling link keeps replacing it
The merge left store_header's visitor unclosed (does not build). R3's pin that a whole-store flush replaces a dangling link survives the single reader: the reader still refuses the link as an I/O error, and the flush, which has no content to carry from a link that holds none, writes v1 over it (Rust write_all_unlocked, TS pushAll). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
bad511f5ac
commit
ff0251bbf8
2 changed files with 29 additions and 2 deletions
|
|
@ -404,6 +404,10 @@ fn store_header(bytes: &[u8]) -> Result<Option<String>> {
|
|||
_ => None,
|
||||
}))
|
||||
}
|
||||
}
|
||||
deserializer.deserialize_seq(HeaderVisitor)
|
||||
}
|
||||
}
|
||||
let mut cursor = std::io::Cursor::new(bytes);
|
||||
let header = <Header as serde::Deserialize>::deserialize(&mut rmp_serde::Deserializer::new(&mut cursor))
|
||||
.map_err(|error| opaque_decode_error(error).context("the store is not one complete MessagePack array"))?;
|
||||
|
|
@ -955,7 +959,13 @@ impl SingleFileMessagePackBackingStore {
|
|||
// payloads this store passes through may hold ids), one that is gone or legacy is written v1. The file is read by
|
||||
// the same reader as an open, so a store this runtime cannot read completely, a variant included, is refused
|
||||
// and never overwritten.
|
||||
let disk = self.read_store_unlocked()?;
|
||||
let disk = match self.read_store_unlocked() {
|
||||
// A dangling link holds no store, so a whole-file replace has no header to keep and replaces the link (R3 pins
|
||||
// this). The only NotFound the reader returns is that one: a merging writer has already refused it when it
|
||||
// read the current entries.
|
||||
Err(error) if io_not_found(&error) => DiskStore::empty(),
|
||||
other => other?,
|
||||
};
|
||||
let bytes = encode_store_snapshot(entries, &disk)
|
||||
.and_then(|snapshot| rmp_serde::to_vec(&snapshot).context("failed to encode MessagePack"))
|
||||
.map_err(|error| error.context(failed(CultCacheStoreWriteFailedKind::Rejected)))?;
|
||||
|
|
@ -2988,6 +2998,12 @@ fn release_lock<T>(lock: File, result: Result<T>) -> Result<T> {
|
|||
result
|
||||
}
|
||||
|
||||
fn io_not_found(error: &anyhow::Error) -> bool {
|
||||
error
|
||||
.chain()
|
||||
.any(|cause| cause.downcast_ref::<std::io::Error>().is_some_and(|io| io.kind() == std::io::ErrorKind::NotFound))
|
||||
}
|
||||
|
||||
/// True only when nothing is at `path`; a symbolic link, dangling or not, is something.
|
||||
/// A path that cannot be inspected (a file where a directory should be, no permission)
|
||||
/// is an error, never absent.
|
||||
|
|
|
|||
|
|
@ -85,7 +85,18 @@ export class SingleFileMessagePackBackingStore implements CacheBackingStore {
|
|||
// stays marked, and one that is not (or is gone, empty or legacy) is written unmarked. The file is read by the same
|
||||
// reader as `pullAll`, so one it would refuse (not exactly one store, a variant, a body it cannot decode) is refused
|
||||
// and left as it is.
|
||||
this.#format = (await this.#readDisk()).format;
|
||||
try {
|
||||
this.#format = (await this.#readDisk()).format;
|
||||
} catch (error) {
|
||||
// Only a dangling link reaches here with ENOENT: it holds no store, so a whole-store flush has no header to keep and
|
||||
// replaces the link (R3 pins this). Every merging writer has already refused it when it read the current entries.
|
||||
if ((error as NodeJS.ErrnoException).code !== "ENOENT") {
|
||||
throw error;
|
||||
}
|
||||
|
||||
this.#format = STORE_FORMAT_VERSION;
|
||||
}
|
||||
|
||||
await this.#writeAll(entries, []);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue