From ee6ddcdc21976e1db0a8ee414d61fa9304459886 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Thu, 21 May 2020 14:48:02 +0200 Subject: [PATCH] Explicitly set the stack size for the MeshLink thread. Different libcs have different default sizes for newly created threads. In particular, Musl defaults to 80 kB, which is too small for MeshLink. We now request 1 MB, which should be more than enough to handle the deepest call stacks. --- src/meshlink.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/meshlink.c b/src/meshlink.c index e50be188..22f5220d 100644 --- a/src/meshlink.c +++ b/src/meshlink.c @@ -1659,7 +1659,12 @@ bool meshlink_start(meshlink_handle_t *mesh) { event_loop_start(&mesh->loop); - if(pthread_create(&mesh->thread, NULL, meshlink_main_loop, mesh) != 0) { + // Ensure we have a decent amount of stack space. Musl's default of 80 kB is too small. + pthread_attr_t attr; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, 1024 * 1024); + + if(pthread_create(&mesh->thread, &attr, meshlink_main_loop, mesh) != 0) { logger(mesh, MESHLINK_DEBUG, "Could not start thread: %s\n", strerror(errno)); memset(&mesh->thread, 0, sizeof(mesh)->thread); meshlink_errno = MESHLINK_EINTERNAL; -- 2.39.5