I am running a C++ program using libprotobuf version 3.7.1, and getting the following FATAL error:
[libprotobuf FATAL /usr/local/include/google/protobuf/message_lite.h:108] CHECK failed: (size) <= (static_cast<size_t>(0x7fffffff)):
This, unfortunately, only occurs once or twice a week on a system handling 200 - 2000 message per second.
Can anyone provide advice on how to go about debugging this issue?
Does this error indicate an issue with libprotobuf or is the problem likely an issue with a call into the library from my code?
Protobuf messages have to be less than 2 GB in size. It looks like you are occasionally hitting that limit with some message. To avoid that crash, I would recommend making sure to always call ByteSizeLong() instead of ByteSize() when you want to determine the serialized size of a message. ByteSize() crashes with that assertion because it returns a signed 32-bit int and therefore can't return a correct answer if the size is 2 GB or higher. ByteSizeLong() will always return the correct answer. You won't be able to serialize the message if it's 2 GB or higher, but you can at least check for that case and handle it without crashing if you call ByteSizeLong().
Thanks @acozzette. I believe this is the help I needed.
Most helpful comment
Protobuf messages have to be less than 2 GB in size. It looks like you are occasionally hitting that limit with some message. To avoid that crash, I would recommend making sure to always call
ByteSizeLong()instead ofByteSize()when you want to determine the serialized size of a message.ByteSize()crashes with that assertion because it returns a signed 32-bit int and therefore can't return a correct answer if the size is 2 GB or higher.ByteSizeLong()will always return the correct answer. You won't be able to serialize the message if it's 2 GB or higher, but you can at least check for that case and handle it without crashing if you callByteSizeLong().