Skip to content

Commit cc12cab

Browse files
mikolalysenkoclaude
andcommitted
Read the stale VEX doc with the FIFO-safe reader
When a vex run fails, remove_stale_vex_doc reads --output/--vex to check it is OpenVEX before deleting it. It used tokio::fs::read, so a FIFO at that path blocked the failed run forever. Use read_regular_to_bytes, as the other user-supplied paths already do. The new covgap test hangs (60s timeout) without the fix. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 7b4dbe0 commit cc12cab

2 files changed

Lines changed: 65 additions & 1 deletion

File tree

‎crates/socket-patch-cli/src/commands/vex.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,9 @@ async fn generate_vex_with_cleanup(
12191219
/// Removal errors are swallowed: the non-zero exit is the contract, the
12201220
/// deletion is hygiene. Returns whether a document was actually removed.
12211221
async fn remove_stale_vex_doc(path: &Path) -> bool {
1222-
let Ok(bytes) = tokio::fs::read(path).await else {
1222+
// FIFO-safe read: `--vex` can name any path, and a plain read of a FIFO
1223+
// there would block this failure path forever.
1224+
let Ok(bytes) = socket_patch_core::utils::fs::read_regular_to_bytes(path).await else {
12231225
return false;
12241226
};
12251227
let is_openvex = serde_json::from_slice::<serde_json::Value>(&bytes)

‎crates/socket-patch-cli/tests/covgap_commands_vex.rs‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,68 @@ fn corrupt_manifest_json_envelope_carries_code_and_removes_stale_doc() {
223223
);
224224
}
225225

226+
/// A failed run's stale-doc cleanup reads `--output` to check it is
227+
/// OpenVEX before deleting it. A FIFO there must not block that read: the
228+
/// run still fails promptly with its own error and leaves the FIFO alone.
229+
#[cfg(unix)]
230+
#[test]
231+
fn failed_run_does_not_block_on_a_fifo_at_output() {
232+
use std::os::unix::fs::FileTypeExt;
233+
use std::time::{Duration, Instant};
234+
let tmp = tempfile::tempdir().unwrap();
235+
let cwd = tmp.path();
236+
let dir = cwd.join(".socket");
237+
std::fs::create_dir_all(&dir).unwrap();
238+
std::fs::write(dir.join("manifest.json"), "{not json").unwrap();
239+
let fifo = cwd.join("out.vex.json");
240+
assert!(Command::new("mkfifo")
241+
.arg(&fifo)
242+
.status()
243+
.unwrap()
244+
.success());
245+
246+
let mut child = cli()
247+
.args([
248+
"vex",
249+
"--cwd",
250+
cwd.to_str().unwrap(),
251+
"--json",
252+
"--output",
253+
fifo.to_str().unwrap(),
254+
"--product",
255+
"pkg:npm/app@1.0.0",
256+
])
257+
.stdin(std::process::Stdio::null())
258+
.stdout(std::process::Stdio::piped())
259+
.stderr(std::process::Stdio::piped())
260+
.spawn()
261+
.expect("invoke vex");
262+
let started = Instant::now();
263+
while child.try_wait().unwrap().is_none() {
264+
if started.elapsed() > Duration::from_secs(60) {
265+
let _ = child.kill();
266+
panic!("vex blocked reading the FIFO at --output");
267+
}
268+
std::thread::sleep(Duration::from_millis(25));
269+
}
270+
let out = child.wait_with_output().unwrap();
271+
assert_eq!(
272+
out.status.code(),
273+
Some(2),
274+
"stdout:\n{}",
275+
String::from_utf8_lossy(&out.stdout)
276+
);
277+
let env: Value = serde_json::from_slice(&out.stdout).expect("envelope JSON on stdout");
278+
assert_eq!(env["error"]["code"], "manifest_unreadable", "{env}");
279+
assert!(
280+
std::fs::symlink_metadata(&fifo)
281+
.unwrap()
282+
.file_type()
283+
.is_fifo(),
284+
"a FIFO is not an OpenVEX document and must not be removed"
285+
);
286+
}
287+
226288
// ──────────────────────────────────────────────────────────────────────
227289
// corrupt pre-v5 redirect ledger → `redirect_ledger_corrupt` WARNING
228290
//

0 commit comments

Comments
 (0)