Heavy usage of TLS causes stack overflow #136120
Labels
A-panic
Area: Panicking machinery
A-thread-locals
Area: Thread local storage (TLS)
C-bug
Category: This is a bug.
T-libs
Relevant to the library team, which will review and decide on the PR/issue.
i wrote a dynamic library which uses
tracing
, which internally usesstd
s TLS implemention.On unix, when I repeatedly load and then unload my library, eventually (after maybe 10 to 20 iterations) the program encounters a stack overflow.
After some research I found that this was due to the following flow:
pthread_key_create
is called when TLS is initialized each time my library is loaded and mytracing
logger is used.pthread_key_delete
is never called, there is no cleanup in this area.Eventually
pthread_key_create
returnsEAGAIN
, which causes a panic.Within the panic, the number of panics for the thread is tracked using TLS so when
increase
is called, we encounter a new panic (due toEAGAIN
), which in turn will panic for the same reason.We enter an endless loop of panics which eventually triggers a stack overflow.
The text was updated successfully, but these errors were encountered: