{"record":{"id":"fa7cd3530704c2a2","repo":"jdx/mise","slug":"remote-cache-blob-pack-ended-before-a-blob-was-com","errorCode":null,"errorMessage":"remote cache blob pack ended before a blob was complete","messagePattern":"remote cache blob pack ended before a blob was complete","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/mise-cache-core/src/lib.rs","lineNumber":844,"sourceCode":"            bail!(\"remote cache blob pack returned a duplicate digest\");\n        }\n        framed_bytes = framed_bytes\n            .checked_add(BLOB_PACK_HEADER_BYTES)\n            .and_then(|bytes| bytes.checked_add(digest.size))\n            .ok_or_else(|| eyre!(\"remote cache blob pack is too large\"))?;\n        payload_bytes = payload_bytes\n            .checked_add(digest.size)\n            .ok_or_else(|| eyre!(\"remote cache blob pack payload is too large\"))?;\n\n        let path = directory.path().join(blobs.len().to_string());\n        let mut output = tokio::fs::File::create(&path).await?;\n        let mut remaining = digest.size;\n        let mut buffer = [0_u8; 64 * 1024];\n        while remaining > 0 {\n            let limit = usize::try_from(remaining.min(buffer.len() as u64)).unwrap();\n            let count = reader.read(&mut buffer[..limit]).await?;\n            if count == 0 {\n                bail!(\"remote cache blob pack ended before a blob was complete\");\n            }\n            output.write_all(&buffer[..count]).await?;\n            hasher.update(&buffer[..count]);\n            remaining -= count as u64;\n        }\n        output.flush().await?;\n        drop(output);\n        if !hasher.matches(&digest.hash) {\n            bail!(\"remote cache blob pack failed digest verification\");\n        }\n        blobs.push((digest, path));\n    }\n    let blob_count = blobs.len().try_into().unwrap_or(u64::MAX);\n    let metadata = metadata.validate(BlobPackResponseStats {\n        blob_count,\n        payload_bytes,\n        framed_bytes,\n    })?;","sourceCodeStart":826,"sourceCodeEnd":862,"githubUrl":"https://github.com/jdx/mise/blob/533346cc374382b41ec5ff70536252b2e96e725c/crates/mise-cache-core/src/lib.rs#L826-L862","documentation":"When streaming a blob out of a remote cache pack, the client reads until the digest's declared size is consumed. If the underlying reader returns EOF (0 bytes) while bytes remain, the pack ended prematurely and the blob would be truncated, so the operation bails instead of writing an incomplete blob.","triggerScenarios":"reader.read() returns Ok(0) inside the while remaining > 0 loop of unpack_blob_pack — the HTTP body/pack stream terminated before delivering digest.size bytes for the current blob.","commonSituations":"Network interruption mid-download, server closing the connection early, truncated response due to proxy timeout, server bug writing fewer bytes than framed.","solutions":["Retry the blob pack download; transient network truncation is the usual cause","Verify the remote cache server writes the full framed payload for each digest","Check proxy/load-balancer idle or body-size timeouts and raise them for large blobs","Confirm content-length handling is not truncating the stream"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"for attempt in 0..3 {\n    match unpack_blob_pack(...).await {\n        Err(e) if e.to_string().contains(\"ended before\") && attempt < 2 => continue,\n        other => break other,\n    }\n}","preventionTips":["Run downloads on stable networks; avoid aggressive proxy idle timeouts","Raise proxy/LB body timeouts for large blobs","Prefer resumable/chunked fetches for very large packs"],"tags":["remote-cache","network","truncated-response"],"backgroundTag":"connection-refused","analyzedSha":"533346cc374382b41ec5ff70536252b2e96e725c","analyzedAt":"2026-09-17T13:35:38.149Z","contentChangedAt":"2026-09-17T13:35:38.149Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}