I am trying to write a server and client that use a line-based text protocol for communication. It works rather well now, but there is some weird problem:

One of my messages loses the first 4 characters. (reproducible, but I don't do anything special in that one case, I think)

boost::asio::async_read_until is used to read the line into a boost::asio::streambuf
the socket is a boost::asio::local::stream_
protocol::socket

std::string msg;
std::istream is(&buffer);
std::getline(is, msg);

I looked at the buffer.size(), the size reported to the handler function and compared it to the length of the message, which looks consistant, so I don't assume that the read call read some characters over the \n. (but that would be the only logical explanation)

* there are no multiple read operations on the socket
* I reuse the same buffer for multiple async_read_until calls

Does anyone have a code snippet that can help me figure out what could be stuck and lost in the buffer, or where else the problem could be?