mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
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:
parent
1de166bccb
commit
0af0a0b445
@ -254,7 +254,7 @@ func (socket *Socket) performWrite() (closed bool) {
|
|||||||
socket.Unlock()
|
socket.Unlock()
|
||||||
|
|
||||||
var err error
|
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:
|
// on Linux, the runtime will optimize this into a single writev(2) call:
|
||||||
_, err = (*net.Buffers)(&buffers).WriteTo(socket.conn)
|
_, err = (*net.Buffers)(&buffers).WriteTo(socket.conn)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user