Description
i wrote a dynamic library which uses tracing
, which internally uses std
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 my tracing
logger is used.
pthread_key_delete
is never called, there is no cleanup in this area.
Eventually pthread_key_create
returns EAGAIN
, 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 to EAGAIN
), which in turn will panic for the same reason.
We enter an endless loop of panics which eventually triggers a stack overflow.