I have a TLS client based on ASIO. The simplified code is roughly as follows:
(Note: All socket operations are protected by mutex, and all ASIO asynchronous callbacks are executed in the same separate threads.)
The problem occurs when the connection is closing. Since the ssl::stream shutdown might be blocking, I directly close the underlying TCP connection. However, I encountered the following occasional crashes on Android/iOS:
So I guessed that after closing the underlying TCP connection, some operations in ssl::stream might still be triggered because the ssl::stream shutdown was not explicitly invoked, which led to the crashes. I then added the SSL layer shutdown process, and the code became like this:
I have a TLS client based on ASIO. The simplified code is roughly as follows: (Note: All socket operations are protected by mutex, and all ASIO asynchronous callbacks are executed in the same separate threads.)
The problem occurs when the connection is closing. Since the ssl::stream shutdown might be blocking, I directly close the underlying TCP connection. However, I encountered the following occasional crashes on Android/iOS:
So I guessed that after closing the underlying TCP connection, some operations in ssl::stream might still be triggered because the ssl::stream shutdown was not explicitly invoked, which led to the crashes. I then added the SSL layer shutdown process, and the code became like this:
After making this change, there were more crashes on the iOS platform, with the following stack trace:
However, it is strange that there are no issues on the Android platform.
Why is this happening, and are there any one who have any suggestions on how to solve this problem?
Thanks!