What surprises me here is -
*) The socket is not closed *) The accept handler of initial async_read_some gets the error ("The I/O operation has been aborted because of either a thread exit or an application request")
*) After that I am able to wait on same socket and read the data from socket. (The async_read_some is again called form the handler of the "initial async_read_some 's accept handler in a recursive manner)
Could there be any other reason for this? This is a multi-threaded application and each socket is created in a new thread, and thread would not exit without completing its execution...
Maybe the thread that calls async_read exits before the relevant completion handler is invoked? By the way, using threads in the way you described in asio-based program is usually a bad idea. The whole point of using async i/o is to avoid such an "explicit" multithreading -- usually one spawns multiple threads to scale for multiple CPUs only. http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html#boost... http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/examples.html#boost...