Skip to content

Commit

Permalink
darwin: use RLIMIT_STACK for fsevents pthread
Browse files Browse the repository at this point in the history
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 <size-kb>`.

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: libuv#3132
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Santiago Gimeno <[email protected]>
  • Loading branch information
gluxon authored and JeffroMF committed May 16, 2022
1 parent ac4d362 commit 75efb06
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/unix/fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 75efb06

Please sign in to comment.