Has anyone seen something similar or have any input on how best to figure out what goes wrong?
We use asio for very intensive streaming/playback, and we never encountered such an issue.
Are there invariants that says you cannot read and write at the same time?
No, you can.
Some symptoms are the same in each test. When we get the last image from the socket the buffersize is zero afterwards, and the next async_read request is to transfer_at_least(1). The async_read never calls the handler for completion of this byte, so Nagle would have kicked in.
One of the main invariants in asio is that every async_read ends with a call of its handler. So you have to check 2 points: 1) ensure that async_read was really called, 2) ensure that the data you're waiting for were *not* received during in the previous call of async_read.