From 67601bbbce6ea1c26191f235afc50007a4e796c5 Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Khan Date: Wed, 24 Jul 2024 10:17:15 -0700 Subject: [PATCH] Bump the minimum stack size to at least 1MB (#1139) --- source/posix/thread.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/source/posix/thread.c b/source/posix/thread.c index af7fac84c..34b5dbe94 100644 --- a/source/posix/thread.c +++ b/source/posix/thread.c @@ -275,6 +275,25 @@ int aws_thread_launch( if (attr_return) { goto cleanup; } + } else if (!options->stack_size) { + /** + * On some systems, the default stack size is too low (128KB on musl at the time of writing this), which can + * cause stack overflow when the dependency chain is long. Increase the stack size to at + * least 1MB, which is the default on Windows. + */ + size_t min_stack_size = (size_t)1 * 1024 * 1024; + size_t current_stack_size; + attr_return = pthread_attr_getstacksize(attributes_ptr, ¤t_stack_size); + if (attr_return) { + goto cleanup; + } + + if (current_stack_size < min_stack_size) { + attr_return = pthread_attr_setstacksize(attributes_ptr, min_stack_size); + if (attr_return) { + goto cleanup; + } + } } /* AFAIK you can't set thread affinity on apple platforms, and it doesn't really matter since all memory