Skip to content

Commit

Permalink
darwin: use default stack size for fsevents pthread on macOS 10.15+
Browse files Browse the repository at this point in the history
This fixes `SIGBUS` crashes on macOS 10.15 due to FSEvents code
attempting to allocate large arrays on the stack.

The existing size (`4 * PTHREAD_STACK_MIN` or 32KB) causes a stack
overflow when more than ~1000 events are received at once. Removing the
manual `pthread_attr_setstacksize` call here defaults to a stack size of
512KB.

Fixes: nodejs/node#37697
Refs: joyent/libuv#964
  • Loading branch information
gluxon committed Mar 12, 2021
1 parent 285a5ea commit a8c5018
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions src/unix/fsevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,6 @@ static int uv__fsevents_global_init(void) {
static int uv__fsevents_loop_init(uv_loop_t* loop) {
CFRunLoopSourceContext ctx;
uv__cf_loop_state_t* state;
pthread_attr_t attr_storage;
pthread_attr_t* attr;
int err;

if (loop->cf_state != NULL)
Expand Down Expand Up @@ -641,25 +639,10 @@ static int uv__fsevents_loop_init(uv_loop_t* loop) {
goto fail_signal_source_create;
}

/* 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.
*/
attr = &attr_storage;
if (pthread_attr_init(attr))
attr = NULL;

if (attr != NULL)
if (pthread_attr_setstacksize(attr, 4 * PTHREAD_STACK_MIN))
abort();

loop->cf_state = state;

/* uv_thread_t is an alias for pthread_t. */
err = UV__ERR(pthread_create(&loop->cf_thread, attr, uv__cf_loop_runner, loop));

if (attr != NULL)
pthread_attr_destroy(attr);
err = UV__ERR(pthread_create(&loop->cf_thread, NULL, uv__cf_loop_runner, loop));

if (err)
goto fail_thread_create;
Expand Down

0 comments on commit a8c5018

Please sign in to comment.