Fix assertion failure in file_tree_read when read operation fails

Initialize *gen to NO_GENERATION at the start of file_tree_read so that
error paths (FILETREE_BADPATH, FILETREE_NOENT, FILETREE_ISDIR) have a
well-defined value. Previously, when file_tree_read failed, gen was
uninitialized, causing the assertion in process_client_read to fire.

The assertion checking gen != NO_GENERATION before the error check was
removed since:
1. On error paths, gen is not used
2. On success paths, the assertion at line 482 already validates gen
This commit is contained in:
Claude
2026-01-16 18:48:23 +00:00
parent 6ef5e1a94c
commit 9948716be8
2 changed files with 3 additions and 1 deletions
+3
View File
@@ -513,6 +513,9 @@ int file_tree_read(FileTree *ft, string path,
uint64_t off, uint64_t len, uint64_t *gen, uint64_t *chunk_size,
SHA256 *hashes, int max_hashes, uint64_t *actual_bytes)
{
// Initialize gen to NO_GENERATION so error paths have a well-defined value
*gen = NO_GENERATION;
int num_comps;
string comps[MAX_COMPS];
-1
View File
@@ -432,7 +432,6 @@ process_client_read(MetadataServer *state, int conn_idx, ByteView msg)
uint64_t actual_bytes;
SHA256 hashes[MAX_READ_HASHES];
int ret = file_tree_read(&state->file_tree, path, offset, length, &gen, &chunk_size, hashes, MAX_READ_HASHES, &actual_bytes);
assert(gen != NO_GENERATION);
if (ret < 0) {