chore: update out-dated node patches (#33421)

This commit is contained in:
Cheng Zhao 2022-03-24 18:26:34 +09:00 committed by GitHub
parent db5a3c014a
commit 9d698c76c5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 22 additions and 196 deletions

View file

@ -33,7 +33,6 @@ be_compatible_with_cppgc.patch
feat_add_knostartdebugsignalhandler_to_environment_to_prevent.patch feat_add_knostartdebugsignalhandler_to_environment_to_prevent.patch
worker_thread_add_asar_support.patch worker_thread_add_asar_support.patch
process_monitor_for_exit_with_kqueue_on_bsds_3441.patch process_monitor_for_exit_with_kqueue_on_bsds_3441.patch
unix_protect_fork_in_uv_spawn_from_signals.patch
process_bsd_handle_kevent_note_exit_failure_3451.patch process_bsd_handle_kevent_note_exit_failure_3451.patch
reland_macos_use_posix_spawn_instead_of_fork_3257.patch reland_macos_use_posix_spawn_instead_of_fork_3257.patch
process_reset_the_signal_mask_if_the_fork_fails_3537.patch process_reset_the_signal_mask_if_the_fork_fails_3537.patch

View file

@ -7,10 +7,10 @@ Subject: feat: add kNoStartDebugSignalHandler to Environment to prevent
This patch should be upstreamed, it allows embedders to prevent the call to StartDebugSignalHandler which handles SIGUSR1 and starts the inspector agent. Apps that have --inspect disabled also don't want SIGUSR1 to have this affect. This patch should be upstreamed, it allows embedders to prevent the call to StartDebugSignalHandler which handles SIGUSR1 and starts the inspector agent. Apps that have --inspect disabled also don't want SIGUSR1 to have this affect.
diff --git a/src/env-inl.h b/src/env-inl.h diff --git a/src/env-inl.h b/src/env-inl.h
index 845e00208af4b12960ed8b3f3926323af7685185..1ebc33324907654d16e9c0e19b2955efbac7cac7 100644 index 2da8174fe9e4209f4705af0a1cf8bca5928f088c..954602f3fc7c3344509bb57530840bb1dfeacab3 100644
--- a/src/env-inl.h --- a/src/env-inl.h
+++ b/src/env-inl.h +++ b/src/env-inl.h
@@ -896,6 +896,10 @@ inline bool Environment::should_initialize_inspector() const { @@ -886,6 +886,10 @@ inline bool Environment::should_initialize_inspector() const {
return (flags_ & EnvironmentFlags::kNoInitializeInspector) == 0; return (flags_ & EnvironmentFlags::kNoInitializeInspector) == 0;
} }
@ -22,10 +22,10 @@ index 845e00208af4b12960ed8b3f3926323af7685185..1ebc33324907654d16e9c0e19b2955ef
return emit_filehandle_warning_; return emit_filehandle_warning_;
} }
diff --git a/src/env.h b/src/env.h diff --git a/src/env.h b/src/env.h
index ab8334bf0e3405fee4d21a4b541bd1164d92ca89..b2537ebd44bc5b37dd97752735f84e87de1f24bf 100644 index 2554c530f2ca7078ed0cca03968b31f56027231b..1fbf965788f9c68d2999f38b40d39579f746d768 100644
--- a/src/env.h --- a/src/env.h
+++ b/src/env.h +++ b/src/env.h
@@ -1207,6 +1207,7 @@ class Environment : public MemoryRetainer { @@ -1216,6 +1216,7 @@ class Environment : public MemoryRetainer {
inline bool hide_console_windows() const; inline bool hide_console_windows() const;
inline bool no_global_search_paths() const; inline bool no_global_search_paths() const;
inline bool should_initialize_inspector() const; inline bool should_initialize_inspector() const;
@ -34,7 +34,7 @@ index ab8334bf0e3405fee4d21a4b541bd1164d92ca89..b2537ebd44bc5b37dd97752735f84e87
inline worker::Worker* worker_context() const; inline worker::Worker* worker_context() const;
Environment* worker_parent_env() const; Environment* worker_parent_env() const;
diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc diff --git a/src/inspector_agent.cc b/src/inspector_agent.cc
index c4a3322c6d972fc2052af75b79389c522924d9c5..39ff8df415be1908ba404fba34d9cedda04a88af 100644 index fd9f514b9b6a7b7b1c1a6f5fe834f51266156596..14565f6885b3f88194b3b8efb340a4099ca1966c 100644
--- a/src/inspector_agent.cc --- a/src/inspector_agent.cc
+++ b/src/inspector_agent.cc +++ b/src/inspector_agent.cc
@@ -680,8 +680,10 @@ bool Agent::Start(const std::string& path, @@ -680,8 +680,10 @@ bool Agent::Start(const std::string& path,
@ -51,10 +51,10 @@ index c4a3322c6d972fc2052af75b79389c522924d9c5..39ff8df415be1908ba404fba34d9cedd
parent_env_->AddCleanupHook([](void* data) { parent_env_->AddCleanupHook([](void* data) {
Environment* env = static_cast<Environment*>(data); Environment* env = static_cast<Environment*>(data);
diff --git a/src/node.h b/src/node.h diff --git a/src/node.h b/src/node.h
index 4201c0d0460b032721ef42a26d79c38a9ee20c24..6873fc89406b046823db9e45234eb7f6b767099d 100644 index b2b766f242e02593631be087fceaf63f71d74284..535df2d8dfb48ddc4d01e94565fdc527aed15ef7 100644
--- a/src/node.h --- a/src/node.h
+++ b/src/node.h +++ b/src/node.h
@@ -425,7 +425,11 @@ enum Flags : uint64_t { @@ -444,7 +444,11 @@ enum Flags : uint64_t {
// Controls whether or not the Environment should call InitializeInspector. // Controls whether or not the Environment should call InitializeInspector.
// This control is needed by embedders who may not want to initialize the V8 // This control is needed by embedders who may not want to initialize the V8
// inspector in situations where it already exists. // inspector in situations where it already exists.

View file

@ -25,7 +25,7 @@ index 16be13b99f5db77741aa276e90a437ef4eb5ba32..2dcc8b32f5165dd75061a1b55cc1abd2
/* flags of excluding ifaddr */ /* flags of excluding ifaddr */
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index 35200f17495d80ed2d19ef9f6f76bbc92ee042f6..071fe0ce0938657d0fb840af62a432352e938a8a 100644 index efbc561dee2574f06ebd9408d1e89e435c93cc5a..857eb1d54bfde99754ce2c6e92a287c288bd9f52 100644
--- a/deps/uv/src/unix/kqueue.c --- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c +++ b/deps/uv/src/unix/kqueue.c
@@ -285,7 +285,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { @@ -285,7 +285,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
@ -37,7 +37,7 @@ index 35200f17495d80ed2d19ef9f6f76bbc92ee042f6..071fe0ce0938657d0fb840af62a43235
nevents++; nevents++;
continue; continue;
} }
@@ -383,6 +383,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { @@ -382,6 +382,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
nevents++; nevents++;
} }

View file

@ -10,7 +10,7 @@ track exactly which processes have exited. Should also be a slight speed
improvement for excessively large numbers of live children. improvement for excessively large numbers of live children.
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index 071fe0ce0938657d0fb840af62a432352e938a8a..4c4d990ff5fa6c8ab937be2e4f79ccdaf90670c2 100644 index 857eb1d54bfde99754ce2c6e92a287c288bd9f52..036055149fcabcb9ff8f43522120c82b3474ab99 100644
--- a/deps/uv/src/unix/kqueue.c --- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c +++ b/deps/uv/src/unix/kqueue.c
@@ -117,6 +117,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { @@ -117,6 +117,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {

View file

@ -23,7 +23,7 @@ index 12d4da93686e993830a7d09e74d08191fc808f4f..16be13b99f5db77741aa276e90a437ef
/* random */ /* random */
int uv__random_devurandom(void* buf, size_t buflen); int uv__random_devurandom(void* buf, size_t buflen);
diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c diff --git a/deps/uv/src/unix/kqueue.c b/deps/uv/src/unix/kqueue.c
index bf183d5fdc0ba89913469a294322eef84bc4cee8..35200f17495d80ed2d19ef9f6f76bbc92ee042f6 100644 index 75e9110709da8d30628449311cb916a26c775ecf..efbc561dee2574f06ebd9408d1e89e435c93cc5a 100644
--- a/deps/uv/src/unix/kqueue.c --- a/deps/uv/src/unix/kqueue.c
+++ b/deps/uv/src/unix/kqueue.c +++ b/deps/uv/src/unix/kqueue.c
@@ -284,6 +284,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { @@ -284,6 +284,11 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
@ -39,10 +39,10 @@ index bf183d5fdc0ba89913469a294322eef84bc4cee8..35200f17495d80ed2d19ef9f6f76bbc9
/* Skip invalidated events, see uv__platform_invalidate_fd */ /* Skip invalidated events, see uv__platform_invalidate_fd */
if (fd == -1) if (fd == -1)
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c
index f4aebb0490e198cd9adcadfeb6b006de479cc993..cfcba341e0e380ecd595e4b59e39c08a7b374a48 100644 index 91bf3c507022b2eddc0d36f40d73a977bf731fbc..c1f6bd4b0076f0835caf83c45a6a896e7ae5def9 100644
--- a/deps/uv/src/unix/process.c --- a/deps/uv/src/unix/process.c
+++ b/deps/uv/src/unix/process.c +++ b/deps/uv/src/unix/process.c
@@ -48,10 +48,20 @@ extern char **environ; @@ -49,10 +49,20 @@ extern char **environ;
# include "zos-base.h" # include "zos-base.h"
#endif #endif
@ -64,7 +64,7 @@ index f4aebb0490e198cd9adcadfeb6b006de479cc993..cfcba341e0e380ecd595e4b59e39c08a
int exit_status; int exit_status;
int term_signal; int term_signal;
int status; int status;
@@ -60,10 +70,7 @@ static void uv__chld(uv_signal_t* handle, int signum) { @@ -61,10 +71,7 @@ static void uv__chld(uv_signal_t* handle, int signum) {
QUEUE* q; QUEUE* q;
QUEUE* h; QUEUE* h;
@ -75,7 +75,7 @@ index f4aebb0490e198cd9adcadfeb6b006de479cc993..cfcba341e0e380ecd595e4b59e39c08a
h = &loop->process_handles; h = &loop->process_handles;
q = QUEUE_HEAD(h); q = QUEUE_HEAD(h);
@@ -419,7 +426,9 @@ int uv_spawn(uv_loop_t* loop, @@ -420,7 +427,9 @@ int uv_spawn(uv_loop_t* loop,
if (err) if (err)
goto error; goto error;
@ -85,7 +85,7 @@ index f4aebb0490e198cd9adcadfeb6b006de479cc993..cfcba341e0e380ecd595e4b59e39c08a
/* Acquire write lock to prevent opening new fds in worker threads */ /* Acquire write lock to prevent opening new fds in worker threads */
uv_rwlock_wrlock(&loop->cloexec_lock); uv_rwlock_wrlock(&loop->cloexec_lock);
@@ -478,6 +487,13 @@ int uv_spawn(uv_loop_t* loop, @@ -495,6 +504,13 @@ int uv_spawn(uv_loop_t* loop,
/* Only activate this handle if exec() happened successfully */ /* Only activate this handle if exec() happened successfully */
if (exec_errorno == 0) { if (exec_errorno == 0) {
@ -100,10 +100,10 @@ index f4aebb0490e198cd9adcadfeb6b006de479cc993..cfcba341e0e380ecd595e4b59e39c08a
uv__handle_start(process); uv__handle_start(process);
} }
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 59b95da9ebe3464bd1f9ce1c534122b1f9e06636..58489c4be7b3a7b36d5b01a1f07d411ef3d99ae3 100644 index 1f566861a0e2e9e29c925972155f49667bb7ce85..a43edf1a4a9b0932ec73b8edaca0f676ecf3ccfa 100644
--- a/deps/uv/test/test-list.h --- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h +++ b/deps/uv/test/test-list.h
@@ -318,6 +318,7 @@ TEST_DECLARE (spawn_reads_child_path) @@ -320,6 +320,7 @@ TEST_DECLARE (spawn_reads_child_path)
TEST_DECLARE (spawn_inherit_streams) TEST_DECLARE (spawn_inherit_streams)
TEST_DECLARE (spawn_quoted_path) TEST_DECLARE (spawn_quoted_path)
TEST_DECLARE (spawn_tcp_server) TEST_DECLARE (spawn_tcp_server)
@ -111,7 +111,7 @@ index 59b95da9ebe3464bd1f9ce1c534122b1f9e06636..58489c4be7b3a7b36d5b01a1f07d411e
TEST_DECLARE (fs_poll) TEST_DECLARE (fs_poll)
TEST_DECLARE (fs_poll_getpath) TEST_DECLARE (fs_poll_getpath)
TEST_DECLARE (fs_poll_close_request) TEST_DECLARE (fs_poll_close_request)
@@ -944,6 +945,7 @@ TASK_LIST_START @@ -950,6 +951,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_inherit_streams) TEST_ENTRY (spawn_inherit_streams)
TEST_ENTRY (spawn_quoted_path) TEST_ENTRY (spawn_quoted_path)
TEST_ENTRY (spawn_tcp_server) TEST_ENTRY (spawn_tcp_server)

View file

@ -1,173 +0,0 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jameson Nash <vtjnash@gmail.com>
Date: Thu, 29 Jul 2021 12:09:51 -0400
Subject: unix: protect fork in uv_spawn from signals
Years ago, we found that various kernels (linux, macOS) were known to
fail if they try to deliver a signal during this syscall, so we prevent
that from happening. They may have fixed those issues, but it is
generally just a bad time for signals to arrive (glibc blocks them here,
for example, including some more internal ones that it won't let us
touch here).
We try to be a bit conservative, and leave many signals unblocked which
could happen during normal execution and should terminate the process if
they do. There is a small race window after the child starts before we
clear the old handlers, if the user was to send an fake signal from
elsewhere, but that should be quite unlikely.
PR-URL: https://github.com/libuv/libuv/pull/3251
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
diff --git a/deps/uv/src/unix/process.c b/deps/uv/src/unix/process.c
index cfcba341e0e380ecd595e4b59e39c08a7b374a48..c1f6bd4b0076f0835caf83c45a6a896e7ae5def9 100644
--- a/deps/uv/src/unix/process.c
+++ b/deps/uv/src/unix/process.c
@@ -26,6 +26,7 @@
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
+#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -223,13 +224,32 @@ static void uv__process_child_init(const uv_process_options_t* options,
int stdio_count,
int (*pipes)[2],
int error_fd) {
- sigset_t set;
+ sigset_t signewset;
int close_fd;
int use_fd;
- int err;
int fd;
int n;
+ /* Reset signal disposition first. Use a hard-coded limit because NSIG is not
+ * fixed on Linux: it's either 32, 34 or 64, depending on whether RT signals
+ * are enabled. We are not allowed to touch RT signal handlers, glibc uses
+ * them internally.
+ */
+ for (n = 1; n < 32; n += 1) {
+ if (n == SIGKILL || n == SIGSTOP)
+ continue; /* Can't be changed. */
+
+#if defined(__HAIKU__)
+ if (n == SIGKILLTHR)
+ continue; /* Can't be changed. */
+#endif
+
+ if (SIG_ERR != signal(n, SIG_DFL))
+ continue;
+
+ uv__write_errno(error_fd);
+ }
+
if (options->flags & UV_PROCESS_DETACHED)
setsid();
@@ -311,32 +331,10 @@ static void uv__process_child_init(const uv_process_options_t* options,
environ = options->env;
}
- /* Reset signal disposition. Use a hard-coded limit because NSIG
- * is not fixed on Linux: it's either 32, 34 or 64, depending on
- * whether RT signals are enabled. We are not allowed to touch
- * RT signal handlers, glibc uses them internally.
- */
- for (n = 1; n < 32; n += 1) {
- if (n == SIGKILL || n == SIGSTOP)
- continue; /* Can't be changed. */
-
-#if defined(__HAIKU__)
- if (n == SIGKILLTHR)
- continue; /* Can't be changed. */
-#endif
-
- if (SIG_ERR != signal(n, SIG_DFL))
- continue;
-
- uv__write_errno(error_fd);
- }
-
- /* Reset signal mask. */
- sigemptyset(&set);
- err = pthread_sigmask(SIG_SETMASK, &set, NULL);
-
- if (err != 0)
- uv__write_errno(error_fd);
+ /* Reset signal mask just before exec. */
+ sigemptyset(&signewset);
+ if (sigprocmask(SIG_SETMASK, &signewset, NULL) != 0)
+ abort();
#ifdef __MVS__
execvpe(options->file, options->args, environ);
@@ -345,6 +343,7 @@ static void uv__process_child_init(const uv_process_options_t* options,
#endif
uv__write_errno(error_fd);
+ abort();
}
#endif
@@ -356,6 +355,8 @@ int uv_spawn(uv_loop_t* loop,
/* fork is marked __WATCHOS_PROHIBITED __TVOS_PROHIBITED. */
return UV_ENOSYS;
#else
+ sigset_t signewset;
+ sigset_t sigoldset;
int signal_pipe[2] = { -1, -1 };
int pipes_storage[8][2];
int (*pipes)[2];
@@ -432,25 +433,41 @@ int uv_spawn(uv_loop_t* loop,
/* Acquire write lock to prevent opening new fds in worker threads */
uv_rwlock_wrlock(&loop->cloexec_lock);
- pid = fork();
- if (pid == -1) {
+ /* Start the child with most signals blocked, to avoid any issues before we
+ * can reset them, but allow program failures to exit (and not hang). */
+ sigfillset(&signewset);
+ sigdelset(&signewset, SIGKILL);
+ sigdelset(&signewset, SIGSTOP);
+ sigdelset(&signewset, SIGTRAP);
+ sigdelset(&signewset, SIGSEGV);
+ sigdelset(&signewset, SIGBUS);
+ sigdelset(&signewset, SIGILL);
+ sigdelset(&signewset, SIGSYS);
+ sigdelset(&signewset, SIGABRT);
+ if (pthread_sigmask(SIG_BLOCK, &signewset, &sigoldset) != 0)
+ abort();
+
+ pid = fork();
+ if (pid == -1)
err = UV__ERR(errno);
- uv_rwlock_wrunlock(&loop->cloexec_lock);
- uv__close(signal_pipe[0]);
- uv__close(signal_pipe[1]);
- goto error;
- }
- if (pid == 0) {
+ if (pid == 0)
uv__process_child_init(options, stdio_count, pipes, signal_pipe[1]);
+
+ if (pthread_sigmask(SIG_SETMASK, &sigoldset, NULL) != 0)
abort();
- }
/* Release lock in parent process */
uv_rwlock_wrunlock(&loop->cloexec_lock);
+
uv__close(signal_pipe[1]);
+ if (pid == -1) {
+ uv__close(signal_pipe[0]);
+ goto error;
+ }
+
process->status = 0;
exec_errorno = 0;
do

View file

@ -7,10 +7,10 @@ This patch initializes asar support in workers threads in
Node.js. Node.js.
diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js
index 419ffd9d5deb84eb94381259d3084411f6c3341b..17a1860d158976f11035553601560d171c7fc25a 100644 index 2af6b11c97ecdca3c40792ab35c69b07b9db76a0..e79ce2b79a5f88a315ac013b6e12534ba1531d6b 100644
--- a/lib/internal/bootstrap/pre_execution.js --- a/lib/internal/bootstrap/pre_execution.js
+++ b/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js
@@ -505,6 +505,7 @@ module.exports = { @@ -498,6 +498,7 @@ module.exports = {
loadPreloadModules, loadPreloadModules,
setupTraceCategoryState, setupTraceCategoryState,
setupInspectorHooks, setupInspectorHooks,
@ -19,7 +19,7 @@ index 419ffd9d5deb84eb94381259d3084411f6c3341b..17a1860d158976f11035553601560d17
initializeCJSLoader, initializeCJSLoader,
initializeWASI initializeWASI
diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js diff --git a/lib/internal/main/worker_thread.js b/lib/internal/main/worker_thread.js
index e3ce67987ee3185a93750ebad72beab304c71e3a..ef5082d73b6153b49875c61d9b365b873b16145d 100644 index 2e5d6b01d86e34549c1c7a3d3128350cad2b0c47..74ab84ca39a01269925ca0e326e4aa8894fce8a1 100644
--- a/lib/internal/main/worker_thread.js --- a/lib/internal/main/worker_thread.js
+++ b/lib/internal/main/worker_thread.js +++ b/lib/internal/main/worker_thread.js
@@ -27,6 +27,7 @@ const { @@ -27,6 +27,7 @@ const {