From 608ac2e4336275fb97e67abf0c51c7d4ecfa9994 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Sat, 13 Mar 2021 16:55:16 -0500 Subject: [PATCH] darwin: use RLIMIT_STACK for fsevents pthread This fixes `SIGBUS` crashes on macOS 10.15 due a new change in `FSEvents.framework` that makes it allocate a large stack array for event paths. (See the linked nodejs/node issue for details on the `FSEvents.framework` memory requirements change itself.) The existing size (`4 * PTHREAD_STACK_MIN` or 32KB) causes a stack overflow when more than ~1000 events are received at once. Setting this to `uv__thread_stack_size()` increases it to 8192KB (by default) on 64-bit machines. This value can be configured at runtime on macOS with `ulimit -s `. The 32KB limit was originally added to reduce virtual memory fragmentation on 32-bit systems, which is not a concern on 64-bit systems. Fixes: nodejs/node#37697 Refs: joyent/libuv#964 PR-URL: https://github.com/libuv/libuv/pull/3132 Reviewed-By: Ben Noordhuis Reviewed-By: Santiago Gimeno --- src/unix/fsevents.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/unix/fsevents.c b/src/unix/fsevents.c index a51f29b3f..e4d1b4167 100644 --- a/src/unix/fsevents.c +++ b/src/unix/fsevents.c @@ -642,15 +642,15 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) { } /* In the unlikely event that pthread_attr_init() fails, create the thread - * with the default stack size. We'll use a little more address space but - * that in itself is not a fatal error. + * with the default stack size. We'll likely use less address space but that + * in itself is not a fatal error. */ attr = &attr_storage; if (pthread_attr_init(attr)) attr = NULL; if (attr != NULL) - if (pthread_attr_setstacksize(attr, 4 * PTHREAD_STACK_MIN)) + if (pthread_attr_setstacksize(attr, uv__thread_stack_size())) abort(); loop->cf_state = state;