On 6/04/2020 06:15, gga wrote:
I am facing a weird crash using boost asio when the client segfaults upon exit on the Release builds of my program after the server has closed the connection. The crash happens upon exit of the application (so my guess it is probably some static destructor crashing), not at the end of the connection to the server. The crash does not occur on the Debug version of my application, nor does asan report any memory trashing. The crash also does not happen if I don't do any network connections in my application (boost::asio does not run any io_services). The crash also happens on Linux only and not on Windows.
I created a relatively smaller client/server program like my executable and there's no crash there either.
I have run out of things to try. Can someone suggest something I can try to see where the crash is happening?
It's difficult to say anything concrete without an MCVE to look at. But crashes with ASIO are almost always the result of getting the handler lifetime wrong, most commonly: - not waiting for run() threads to actually stop before starting to delete objects - using multiple run() threads without appropriate locking or strands - not keeping buffer objects alive until their handler is called - trying to re-use buffer objects inappropriately in multiple async calls - not using shared_ptr to manage lifetime of operation objects, or using them incorrectly - doing something that causes a double-free of memory Keep trying to make an MCVE. If you can find one that doesn't crash and one that does, then the difference between the two may prove enlightening.