I am using libpg_query
from Scala. To do so I created a JNI API which uses Protobuf to communicate with the library. Unfortunately SBT build occasionally crashes the whole JVM due to an uncaught exception from the libpg_query
.
[libprotobuf ERROR google/protobuf/descriptor_database.cc:641] File already exists in database: protobuf/pg_query.proto
[libprotobuf FATAL google/protobuf/descriptor.cc:1371] CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
libc++abi.dylib: terminating with uncaught exception of type google::protobuf::FatalException: CHECK failed: GeneratedDatabase()->Add(encoded_file_descriptor, size):
This error seems to be well known - usually caused by doubly linking a Protobuf generated sources to a single binary. That causes reinitialization of the generated classes and a crash of the binary.
In my case that is likely not the root cause. I think that it is caused by the fact that the JNI library can be loaded multiple times from different class loaders and JVM forks - which there is plenty of since I am using the JNI function built in one module as part of macro executed in a subsequent module.
Please, does anyone have an idea how the descriptor_database
gets initialized and whether I can prevent the error from happening in my scenario?