The ý symbol indicates a bunch of debug memory pickups :

This means that streambuf pointers are corrupted.
I do not have a complete picture for your program, but I notice that you are not correctly synchronizing the read / write on the socket.
Dispatch side
For example, looking at MyClass::Send , it joins the existing m_sendBuffer , but sends it again using async_write . it
The usual fix approach is to have a queue of outgoing buffers, not one, and send them sequentially, for example. boost asio async_write: how not to alternate async_write calls?
Reception Party
Here I do not see active problems. However, the same problems on the sending side still apply.
Once you have undefined behavior, you can expect any behavior as well as influence reception behavior.
Most importantly, the read loop leads to the existence of a data broadcast on m_socket : Send starts from ProcessingThreadProc , while the async_read loop runs in the service stream (s).
m_socket thread m_socket
The tcp::socket class is not thread safe. Since you have a worker thread, as well as a thread that runs io_service (and therefore completion handlers), you cannot access m_socket without synchronization.
You must use strand to serialize operations with the m_socket shared object. In this case, access to m_socket already secure inside completion handlers running on this chain. All other calls should be sent in a lock, for example:
m_strand.post([this] { auto callback = boost::bind(&MyClass::OnSend, this, boost::asio::placeholders::error); async_write(m_socket, m_sendBuffer, m_strand.wrap(callback)); });
In fact, you can use the chain to synchronize access to the m_numPostedSocketIO variable, but this will remove the full duplex ability of read / write operations. In addition, you do not need the m_numPostedSocketIO counter:
Close socket
Note that closing a socket already cancels all pending asynchronous I / O. They will be populated with the error code boost::asio::error::operation_aborted .
This means that you can simplify the part in which you are waiting for the completion of pending I / O. You can just close the socket. Notes:
- If you have multiple service flows, you have a line for serializing operations.
in this case, to prevent unsynchronized access to m_socket , the message in the line:
m_strand.post([this] { m_socket.close(); });