Q:

What happens to messages sent by sending socket but never read by receiving socket?

Suppose that I have a sender socket and receiver socket. The sender socket sends messages which are 1 GB in total, but the receiver socket neither read from nor close the socket.
What happens to the 1GB of messages before either socket closes? Are they sitting somewhere in OS buffer?
To be more specific...

Each sender has its own thread.
All senders have flushed their output stream.
All messages are passed by loopback interface

A:

Yes the data will be sitting in buffers in the TCP/IP stack. Though it is far far less than 1Gb.
Assuming you use TCP - which employs flow control to deal with such a situation, the receiver buffers will fill up. When the receiver buffer is full the sender will stop transmitting. The sender buffer will fill up, and when it is full, the application write/send calls will block until the receiver starts consuming the data or an error occurs

