fix a race condition

Setting `closed` on the socket (which can mean either "the socket is broken"
or "we should close the socket at the next opportunity") was racing against
the final write. Even if socket.closed is true, we should attempt to send
buffered message data to the socket, before we send the `finalData` and
actually call `Close`.
This commit is contained in:
Shivaram Lingamneni 2019-05-22 16:25:28 -04:00
parent 1de166bccb
commit 0af0a0b445
1 changed files with 1 additions and 1 deletions

View File

@ -254,7 +254,7 @@ func (socket *Socket) performWrite() (closed bool) {
socket.Unlock()
var err error
if !closed && len(buffers) > 0 {
if 0 < len(buffers) {
// on Linux, the runtime will optimize this into a single writev(2) call:
_, err = (*net.Buffers)(&buffers).WriteTo(socket.conn)
}