akumuli/Akumuli

Exception handling strategy

GeoffreyRobert opened this issue · 4 comments

Hello, I have a question regarding the way exceptions generated by libakumuli can be handled. Currently, in libakumuli/util.h, we have:

/** Panic macro.
  * @param msg error message
  * @throws Exception.
  */
#define AKU_PANIC(msg) Akumuli::invoke_panic_handler(msg); throw 1;

And in libakumuli/util.cpp:

// coverity[+kill]
void invoke_panic_handler(const char* message) {
    (*g_panic_handler)(message);
    Logger::msg(AKU_LOG_ERROR, message);
    std::terminate();
}

Why the call to std::terminate ? Why is it followed by a throw in AKU_PANIC ?
Correct me if I'm wrong but this prevents a library consumer to catch anything and I believe it can cause problems as it won't properly destroy existing objects.

Lazin commented

This function is supposed to kill the application. It's called only if some important invariant is broken and it's impossible to proceed because it's not possible to tell what the app will do next. For instance, the memory corruption could lead to this. In this case the only way to preserve the data integrity is to fail. The errors that could be handled by the client code are represented by the error codes (AKU_Exxx). So if the client of the library provides panic handler, this handler should call terminate/abort. And TBH, I can't remember why I added that throw 1 at the end.

Ok that makes sense, thanks for the answer.
I asked the question because I had some issues running unit tests from test_column_store and test_storage that ended up aborted.
The termination originated back to the MetadataStorage constructor, but with no hint other than SIGABORT was a bit hard to track.

Note for those with a similar issue : I used conan as dependency manager and the package recipe for apache-apr-util did not properly link to sqlite3. So when building your dependencies from source, you solve the issue by using:

./configure ... --with-sqlite3=/path/to/sqlite3/root/dir/ ...

With root/dir/ being above include/ and lib/.

Lazin commented

It's because of apr-util-sqlite library, it's loaded dynamically so all utils that generate dependencies don't work correctly. I solved this issue for RPM and and dpkg.

Ok, thank you for your time.