Crash in libEOSSDK-Linux-Shipping.so

Hi, we encountered a crash in the Linux version of the EOS SDK.

The stack trace (from v1.19.0.7 SDK, but I reproduced the same issue on latest version):

```

Fatal error: [File:Unknown] [Line: 50]

#

# Fatal error in: ../../../rtc_base/platform_thread.cc, line 219

# last system error: 0

# Check failed: 0 == pthread_create(&handle, &attr, &RunPlatformThread, start_thread_function_ptr) (0 vs. 22)

#

```

```

Thread 109 “EOSP2PNetwork” received signal SIGABRT, Aborted.

__pthread_kill_implementation (no_tid=0, signo=6, threadid=4850133759552) at ./nptl/pthread_kill.c:44

44 ./nptl/pthread_kill.c: No such file or directory.

(gdb) bt

#0 __pthread_kill_implementation (no_tid=0, signo=6, threadid=4850133759552) at ./nptl/pthread_kill.c:44

#1 __pthread_kill_internal (signo=6, threadid=4850133759552) at ./nptl/pthread_kill.c:78

#2 __GI___pthread_kill (threadid=4850133759552, signo=signo@entry=6) at ./nptl/pthread_kill.c:89

#3 0x7fffe3e42476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26

#4 0x7fffe3e287f3 in __GI_abort () at ./stdlib/abort.c:79

#5 0x7ffff483ee39 in () at /libEOSSDK-Linux-Shipping.so

…

#15 0x7fffe3e94ac3 in start_thread (arg=<optimized out>) at ./nptl/pthread_create.c:442

#16 0x7fffe3f268d0 in clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:81

```

The hardcoded stack size of 1MB in rtc_base/platform_thread.cc is too little probably because of TLS we use, I managed to locally work around this by the LD_PRELOAD trick with this file:

```cpp

int pthread_attr_setstacksize(pthread_attr_t *attr, size_t stacksize) {

if (stacksize < 4 * 1024 * 1024) {

stacksize = 4 * 1024 * 1024;

}

int (*orig_setstacksize)(pthread_attr_t *, size_t) = dlsym(RTLD_NEXT, “pthread_attr_setstacksize”);

return orig_setstacksize(attr, stacksize);

}

```

But we cannot use the LD_PRELOAD trick in customer builds, can you increase the stack size request to 4MB on your side, or expose a C API we can use to set the limit ourselves? Thank you.

Adam

Your analysis is right, and this was a bug on our side. The SDK’s own threads already add glibc’s TLS-aware minimum on top of the stack size they request, but the threads WebRTC creates for P2P used a fixed 1MB request without that adjustment, so pthread_create fails with EINVAL once your static TLS goes past about 1MB.

Rather than a fixed 4MB or a new stack size API, we’ve fixed it by applying the same TLS adjustment to the WebRTC threads inside the SDK. We reproduced your crash and confirmed the fix with up to 7MB of static TLS. It’s going through review now and will ship in a future SDK release; it will be listed in the release notes.

In the meantime you don’t need LD_PRELOAD. Compile the same pthread_attr_setstacksize override into your game executable and export it to its dynamic symbol table (link with -Wl,–export-dynamic, or -Wl,–dynamic-list with just that symbol). It takes precedence over glibc for calls from libEOSSDK, the same way your preload does. Keep in mind it applies to every thread in the process. I reproduced your crash on 1.19.1.2 and confirmed this workaround avoids it there, but please validate it against your own build before shipping, and let me know if it doesn’t hold.