Recently I’ve seen a very weird core dump in someone’s code that only happens under very specific conditions: we only observer it when the corresponding part of our C++ service experiences an unusually high load.
As the code and many other details are under NDA, I’ll try to emulate the piece of code that crashes:
std::string funcThatAppendsCharToString(std::string_view a, std::string_view b) {
std::string x = (a ? a : "part1");
std::string y = (b ? b : "part2");
std::string ret = x;
ret += '.';
ret += y;
return ret;
}
The crash seems to be happening when appending a dot (‘.’) to the string, specifically in the allocator. Apart from the questionable code practices used here, I cannot think of a reason why a coredump could possibly happen. The only clue I can get is that at the moment of the crash the service runs on around 300 threads, so could this be an issue with thread safety of some sort? Also, there’s no shortage of memory at the time of the crash
It’s hard to think of a solution at this point, except for reducing the number of allocations, but at this point it’s hard to test this theory. What i’m looking for is a possible explanation of the phenomenon
user26867304 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6