Skip to content

Raise the default thread stack on musl - #5

Closed
Wroud wants to merge 1 commit into
opencollab-incubator:mainfrom
Wroud:musl-thread-stack
Closed

Wroud wants to merge 1 commit into
opencollab-incubator:mainfrom
Wroud:musl-thread-stack

Conversation

@Wroud

@Wroud Wroud commented Oct 19, 2026

Copy link
Copy Markdown

musl starts every new thread with a 128 KiB stack and ignores RLIMIT_STACK, so libdatachannel's worker threads get 128 KiB. When one of them attaches to the JVM to deliver a callback, HotSpot on aarch64 reserves most of that stack for its guard and shadow pages and the call into Java overflows. Incoming data channels are acked natively but onDataChannel never runs (GeyserMC/Geyser#6807).

JNI_OnLoad now raises the process default thread stack to 1 MiB with pthread_setattr_default_np on non-glibc Linux, before rtcPreload() starts the threads. glibc and the other platforms are unchanged.

Tested on linux-musl-aarch64 (Alpine 3.24, Temurin 25): built with compileNativeForLinuxMuslAarch64 and swapped into Geyser 2.12.0-b1265, a NetherNet join that previously timed out after 30 s reaches login in under a second, the same as on glibc; with the bundled native the same join times out.

musl starts every new thread with a 128 KiB stack and ignores RLIMIT_STACK. When one of libdatachannel's worker threads attaches to the JVM to deliver a callback, HotSpot reserves most of that stack for its guard and shadow pages, so the call into Java overflows. JNI_OnLoad now raises the default to 1 MiB on non-glibc Linux before rtcPreload() starts the threads.
@irrld

irrld commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Merged with c2d3c9a

@irrld irrld closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants