Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reset signal pipe handler #28383

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ pub fn main() {

setup_panic_hook();

util::unix::restore_sigpipe();
util::unix::raise_fd_limit();
util::windows::ensure_stdio_open();
#[cfg(windows)]
Expand Down
3 changes: 3 additions & 0 deletions cli/tools/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ use crate::util::fs::collect_specifiers;
use crate::util::path::get_extension;
use crate::util::path::is_script_ext;
use crate::util::path::matches_pattern_or_exact_path;
use crate::util::unix::ignore_sigpipe;
use crate::worker::CliMainWorkerFactory;
use crate::worker::CoverageCollector;
use crate::worker::CreateCustomWorkerError;
Expand Down Expand Up @@ -1562,6 +1563,8 @@ pub async fn run_tests(
flags: Arc<Flags>,
test_flags: TestFlags,
) -> Result<(), AnyError> {
ignore_sigpipe();

let factory = CliFactory::from_flags(flags);
let cli_options = factory.cli_options()?;
let workspace_test_options =
Expand Down
20 changes: 20 additions & 0 deletions cli/util/unix.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
// Copyright 2018-2025 the Deno authors. MIT license.

/// Restore the default SIGPIPE handler.
pub fn restore_sigpipe() {
#[cfg(unix)]
// SAFETY: setting SIG_DFL is generally safe as it will restore the default
// behavior. We don't worry about race conditions as this function is called
// on startup.
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_DFL);
}
}

/// Ignore SIGPIPE.
pub fn ignore_sigpipe() {
#[cfg(unix)]
// SAFETY: sets the same signal handler expected by Rust.
unsafe {
libc::signal(libc::SIGPIPE, libc::SIG_IGN);
}
}

/// Raise soft file descriptor limit to hard file descriptor limit.
/// This is the difference between `ulimit -n` and `ulimit -n -H`.
pub fn raise_fd_limit() {
Expand Down
6 changes: 0 additions & 6 deletions tests/integration/run_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2508,7 +2508,6 @@ fn broken_stdout() {

assert!(!output.status.success());
let stderr = std::str::from_utf8(output.stderr.as_ref()).unwrap().trim();
assert!(stderr.contains("Uncaught (in promise) BrokenPipe"));
assert!(!stderr.contains("panic"));
}

Expand All @@ -2530,11 +2529,6 @@ fn broken_stdout_repl() {

assert!(!output.status.success());
let stderr = std::str::from_utf8(output.stderr.as_ref()).unwrap().trim();
if cfg!(windows) {
assert_contains!(stderr, "The pipe is being closed. (os error 232)");
} else {
assert_contains!(stderr, "Broken pipe (os error 32)");
}
assert_not_contains!(stderr, "panic");
}

Expand Down