From 0af0a0b4457e0719c01541092cc7cce04d5fe6ea Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Wed, 22 May 2019 16:25:28 -0400 Subject: [PATCH] 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`. --- irc/socket.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/irc/socket.go b/irc/socket.go index f73d3b3d..e7c8887d 100644 --- a/irc/socket.go +++ b/irc/socket.go @@ -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) }