forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-tmpsweep': close out the shared-temp-path race class

Browse files at this commit

41140987fcd23e33bfa899c688959302d9a93f87Ahmet Kaan GümüşParent: f9d5fb93c9d243
Repo-wide audit of every process::id()-keyed temp path after 9b60697:
ec-h264's ffmpeg_decode and x264_encode_qp keyed theirs by stream
length and qp value -- six and two concurrent tests respectively could
collide on the same name -- and now carry a per-call sequence number.
The twelve other sites are safe by construction: a single test per
binary, or a distinct literal name per caller.
crates/ec-h264/tests/encode.rsmodified+16 -3
@@ -437,9 +437,17 @@ fn have_ffmpeg() -> bool {
437437
438438 /// Decode an Annex B stream with ffmpeg, returning one I420 triple per picture.
439439 fn ffmpeg_decode(stream: &[u8], w: usize, h: usize, extra: &[&str]) -> Option<Vec<Planes>> {
440+ // Distinct per call, not per process: several #[test]s in this binary
441+ // call this on parallel threads, and a path keyed only on stream length
442+ // lets one call's cleanup delete another's still-being-read file.
443+ static SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
440444 let dir = std::env::temp_dir().join(format!("ec-h264-enc-{}", std::process::id()));
441445 std::fs::create_dir_all(&dir).ok()?;
442- let path = dir.join(format!("s{}.264", stream.len()));
446+ let path = dir.join(format!(
447+ "s{}-{}.264",
448+ stream.len(),
449+ SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed)
450+ ));
443451 std::fs::write(&path, stream).ok()?;
444452 let mut cmd = std::process::Command::new("ffmpeg");
445453 cmd.args(["-v", "error"]);
@@ -1010,10 +1018,15 @@ fn have_x264() -> bool {
10101018 /// off so both encoders spend bits by the same rule. Returns the Annex B
10111019 /// stream.
10121020 fn x264_encode_qp(sources: &[Planes], w: usize, h: usize, qp: i32, gop: u32) -> Option<Vec<u8>> {
1021+ // Distinct per call, not per process: two #[test]s in this binary call
1022+ // this on parallel threads with overlapping qp values, and a path keyed
1023+ // only on qp lets one call's cleanup delete another's still-in-use file.
1024+ static SEQ: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
1025+ let seq = SEQ.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
10131026 let dir = std::env::temp_dir().join(format!("ec-h264-x264-{}", std::process::id()));
10141027 std::fs::create_dir_all(&dir).ok()?;
1015- let raw = dir.join(format!("in-q{qp}.yuv"));
1016- let out = dir.join(format!("out-q{qp}.264"));
1028+ let raw = dir.join(format!("in-q{qp}-{seq}.yuv"));
1029+ let out = dir.join(format!("out-q{qp}-{seq}.264"));
10171030 let mut buf = Vec::with_capacity(sources.len() * w * h * 3 / 2);
10181031 for (y, u, v) in sources {
10191032 buf.extend_from_slice(y);