Segfault and crash embedding when julia runs multithreaded gc

I suspect Houdini is continuously updating the SIGSEGV handler just before it calls into the plugin code. As otherwise I don’t see why the handler set by jl_init() would not stay around (and Houdini would never know of the SIGSEGVs). I mean, do you ever see a crash on the first call to the SOP, or only on subsequent calls (after Julia has already been initialized, but Houdini might have restored its own signal handlers)?

If so, then this dirty hack could be worth a try. Directly after calling jl_init() save the current SIGSEGV handler information with sigaction(SIGSEGV, NULL, &julia_sigsegv_action). The julia_sigsegv_action variable is of type struct sigaction and needs to be stored somewhere it can outlive the call to cookMySop. Then, whenever cookMySop is called but Julia is already initialized restore Julia’s handler with sigaction(SIGSEGV, &julia_sigsegv_action, NULL). I’m curious if that works arounds the issue of Houdini catching the SIGSEGVs.

Finally, just as another test, if I use the below I can see dozens of SIGSEGV signals passing by :slight_smile:

void handler(int signum)
{
    fprintf(stderr, "GOT SIGSEGV\n");
}

void *func(void*)
{   
    jl_init();  
    
    // Install own handler, i.e. like Houdini
    signal(SIGSEGV, handler);
    
    jl_eval_string("println(Threads.nthreads())");
    jl_eval_string("x=[1]; @time Threads.@threads for i in 1:100 global x=hcat(x,size(rand(10000,1000))); end");
    jl_atexit_hook(0);
    
    return NULL;
}

int main() 
{    
    pthread_t t;   
    pthread_create(&t, NULL, func, NULL);
    pthread_join(t, NULL);
}
1 Like