Search code examples
c++multithreadingsegmentation-faultwt

C++: If a segfault or something similar happens, is there a way to kill the single thread but keeping the application running?


More or less the subject explains the question. I'm building a web application with C++ and Wt. Of course I'm trying to be particularly careful with things that can cause a segfault, but it might happen. Wt creates a separate thread for every user opening a session. My worst fear is, specifically, that a malicious user finds a bug, which for example produces a segfault, and manages to exploit it, making the whole application crash at whim.

The preferred behaviour instead would be that I can "catch" the signal (yes, I know segfault isn't an exception, this is why I've used the quotes), kill the thread which produced it, maybe, if possible, freeing the memory it allocated and then keep the application running for the other users.

Is it possibile?

Thanks.


Solution

  • There's a possibility to side-step this issue, by specifying a session management configuration option. As such you can assign each session to a separate process, which would crash on segfault, but it would not impact other sessions.

    Detail remark: Wt doesn't really create a thread for each session, it uses a pool of threads to schedule work on.