Skip to content

Commit 7361306

Browse files
committed
Fix FIFO hang in npm v4 lockfile package.json read
Replace bare std::fs::read_to_string with read_regular_to_string_sync in has_native_patch to prevent indefinite blocking on FIFOs or device files planted at package.json path. The guard uses O_NONBLOCK open + fstat regular-file check, matching lockfile reads in select_lockfile and other package.json readers throughout the npm vendor stack.
1 parent b3eaff4 commit 7361306

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎crates/socket-patch-core/src/vendor/npm_lock.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use serde_json::Value;
2222
use crate::constants::SOCKET_DIR;
2323
use crate::manifest::schema::PatchRecord;
2424
use crate::patch::apply::PatchSources;
25-
use crate::utils::fs::{atomic_write_bytes_preserving_mode, read_regular_to_bytes};
25+
use crate::utils::fs::{atomic_write_bytes_preserving_mode, read_regular_to_bytes, read_regular_to_string_sync};
2626
use crate::utils::socket_dir::remove_tree_and_prune;
2727

2828
use super::common::{parse_json_manifest, refused, JsonLayout};
@@ -487,7 +487,7 @@ fn lock_version_gate(
487487
/// `patchedDependencies` key, or a non-null `patched` record on a lock
488488
/// entry. Only the refusal path calls it, so the blocking read is rare.
489489
fn has_native_patch(lock: &Value, project_root: &Path) -> bool {
490-
let manifest = std::fs::read_to_string(project_root.join("package.json")).ok();
490+
let manifest = read_regular_to_string_sync(&project_root.join("package.json")).ok();
491491
if !super::bun_lock_text::patched_dependency_keys(manifest.as_deref(), None).is_empty() {
492492
return true;
493493
}

0 commit comments

Comments
 (0)