Skip to content

SIGSEGV during exit (Safely exit the program from within the Runtime)

I can reproduce this crash. It happens when a thread calls exit and the cleanup code while another thread is using the runtime under destruction.

Thread 5 receives SIGSEGV in Scheduler::schedule because the Runtime object and its Scheduler member are garbage values.

(gdb) i threads
  Id   Target Id                                            Frame 
  1    Thread 0x7ffff79b5280 (LWP 444113) "TellActorFromAn" 0x00007ffff7ce79ba in __futex_abstimed_wait_common64 () from /usr/lib/libpthread.so.0
  2    Thread 0x7ffff79af640 (LWP 444148) "TellActorFromAn" 0x00007ffff7bfca9d in syscall ()
   from /usr/lib/libc.so.6
  3    Thread 0x7ffff71ae640 (LWP 444149) "TellActorFromAn" 0x00007ffff7ce79ba in __futex_abstimed_wait_common64 () from /usr/lib/libpthread.so.0
  4    Thread 0x7ffff69ad640 (LWP 444150) "TellActorFromAn" 0x00007ffff7ce79ba in __futex_abstimed_wait_common64 () from /usr/lib/libpthread.so.0
* 5    Thread 0x7ffff61ac640 (LWP 444153) "TellActorFromAn" 0x0000555555560640 in Scheduler::schedule (
    this=0xfd284c0940fe485, fiber=...) at ../emper/Scheduler.hpp:60
  6    Thread 0x7ffff59ab640 (LWP 444156) "TellActorFromAn" 0x00007ffff7fdc272 in _dl_fini ()
   from /lib64/ld-linux-x86-64.so.2

runtime and scheduler objects seen by Thread 5

Scheduler object in Scheduler::schedule

(gdb) p *this
Cannot access memory at address 0xfd284c0940fe485

Runtime object in Runtime::schedule

(gdb) up
#1  0x0000555555560786 in Runtime::schedule (this=0x7ffff7fdc0e7 <_dl_fini+119>, fiber=...)
    at ../emper/Runtime.hpp:168
168			scheduler.schedule(fiber);
(gdb) p *this
$1 = {<Logger<(LogSubsystem)6>> = {<No data fields>}, static currentRuntimeMutex = 
    {<std::__mutex_base> = {_M_mutex = {__data = {__lock = 0, __count = 0, __owner = 0, __nusers = 0, 
          __kind = 0, __spins = 0, __elision = 0, __list = {__prev = 0x0, __next = 0x0}}, 
        __size = '\000' <repeats 39 times>, __align = 0}}, <No data fields>}, 
  static currentRuntime = 0x7fffffffe040, workerCount = 19339, 
  newWorkerHooks = std::vector of length 132845363851615715, capacity -267351304115112441 = {
    <error reading variable>
(gdb) p this
$2 = (Runtime * const) 0x7ffff7fdc0e7 <_dl_fini+119>

Thread 6 is destructing the process resulting in an invalid Runtime object

(gdb) thread 6
[Switching to thread 6 (Thread 0x7ffff59ab640 (LWP 444156))]
#0  0x00007ffff7fdc272 in _dl_fini () from /lib64/ld-linux-x86-64.so.2
(gdb) bt
#0  0x00007ffff7fdc272 in _dl_fini () from /lib64/ld-linux-x86-64.so.2
#1  0x00007ffff7b42697 in __run_exit_handlers () from /usr/lib/libc.so.6
#2  0x00007ffff7b4283e in exit () from /usr/lib/libc.so.6
#3  0x00007ffff7f26edb in invokeTest () at ../tests/test-runner/test-runner.cpp:14
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
Edited by Maxim Onciul