rust-lang / rust-lang/rust

Rustc version 1.94.1 fails with error "fatal runtime error: out of TLS keys, aborting"

Open
#155,758 22 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-thread-locals C-bug I-crash O-haiku regression-from-stable-to-stable T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

View all comments

After the Rust toolchain got updated from 1.89.0 to 1.94.1 on Haiku OS, I noticed that my project now fails to build with error:

fatal runtime error: out of TLS keys, aborting

out of TLS keys, aborting (screenshot) Image

I suppose here "TLS" refers to thread-local storage rather than transport layer security 🤔

So, it would seem that the new version of rustc attempts to use more TLS slots (keys) than the operating system can provide.

From what I understand, the maximum number of TLS (thread-local storage) keys is equal to PTHREAD_KEYS_MAX, i.e., the "Maximum number of data keys that can be created by a process". It appears that this constant is platform-specific, but the POSIX standard defines the "Minimum Acceptable Value" as another constant called _POSIX_THREAD_KEYS_MAX – which is defined as 128.

See here:
https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html


So, this means that rustc probably should be very conservative with the number of TLS keys that it uses, because one must not assume that more than 128 TLS keys are available on any operating system. Nonetheless, it appears that Rust 1.94.1 violates the limit, whereas older Rust versions, such as 1.89.0, have been working flawlessly 😕

To make it clear, the exactly same code used to compile just fine with Rust 1.89.0 on Haiku OS. Also, my code does not even use thread_local! at all! So, I think, this must be a problem with the excessive use of thread_local! in rustc itself, not in my own code. Furthermore, the problem only started after Haiku OS updated their Rust toolchain from 1.89.0 to 1.94.1, so the "problematic" change must be anywhere in between these versions. I cannot say which version exactly broke the build, since rustup does not support Haiku OS yet, so I can only use the Rust version that Haiko OS itself provides (via pkgman).

Best regards.


Might be related:
https://github.com/rust-lang/rust/issues/147590

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the build failure on Haiku OS with rustc 1.94.1, then compare it with 1.89.0 and investigate the change in thread-local storage key usage between those versions. The issue names no source files or tests, so first locate the compiler or runtime component that allocates TLS keys. Done means the failing project builds without exhausting the platform's TLS keys, with regression coverage where appropriate.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.