5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 03:41:37 +00:00

recover if we try to send to a closed session worker due to a race between a Conn.Write call and a Conn.Close call

This commit is contained in:
Arceliar 2019-06-29 18:50:21 -05:00
parent 28db566b37
commit d39428735d

View File

@ -236,6 +236,11 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
timer := getDeadlineTimer(&c.writeDeadline)
defer util.TimerStop(timer)
// Hand over to the session worker
defer func() {
if recover() != nil {
err = errors.New("write failed")
}
}() // In case we're racing with a close
select { // Send to worker
case sinfo.worker <- workerFunc:
case <-timer.C: