
Jon Biggar wrote:
From my experience, this is likely due to trying to invoke a member function on a lock that is already destroyed. You probably have a race condition where you are doing something on the ASIO socket after it's already been destroyed.
The only thread who can destroy the instance of the object (the asio socket instance is a member of this object) is the io_service running thread. The destroy instruction is in a receive error handler : I cancel timer, close the socket and destroy the instance ; could the timeout handler (which seems to cause the crash) be executed after the destruction of the object ? Maybe my design is bad, what would be a proper way to handle socket timeout and socket explicit close ? My design looks like : explicit_close() { timer.cancel() ; // triggers handle_timeout socket.cancel() ; } handle_timeout() { socket.close() ; // this triggers the handle_receive() function } handle_receive() { if(! error) {} else{timer.cancel() ; socket.close() ; delete this ;} }