Open SiyiJia opened 2 years ago
I see there is a similar one https://github.com/boostorg/asio/issues/328 raised before.
Likely what you're seeing here is that the other end dropped the connection (or some intervening device did; the effect is the same) between the time that you accepted the connection and when you called remote_endpoint()
. No matter how small that window of time is, that's what may have occurred.
That being the case, your two options here are to wrap that call in a try...catch
, or to use the non-throwing form of the call, where you supply an error_code
to the call, e.g., socket.remote_endpoint(ec)
. That form will return a default-constructed endpoint in the case of error.
My program crashes in the following call stack.
The exception is from https://github.com/boostorg/asio/blob/develop/include/boost/asio/basic_socket.hpp#L1625
I don't understand the reason that throws the exception here, can someone help to take a look? Additionally, can we make a fix to catch the exception and gracefully return the error instead of crashing the whole progrm? Thanks!