From d39428735df66a39acef3da98c2ca3eac5237a15 Mon Sep 17 00:00:00 2001 From: Arceliar Date: Sat, 29 Jun 2019 18:50:21 -0500 Subject: [PATCH] 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 --- src/yggdrasil/conn.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/yggdrasil/conn.go b/src/yggdrasil/conn.go index 38e4df9f..b4f68e18 100644 --- a/src/yggdrasil/conn.go +++ b/src/yggdrasil/conn.go @@ -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: