From 86c30a1fc4f918463e70571befbc07bf6b10622b Mon Sep 17 00:00:00 2001 From: Arceliar Date: Mon, 1 Jul 2019 18:55:07 -0500 Subject: [PATCH] fix another panic from a send on a closed session worker channel, from races between Conn.Read/Write/Close --- src/yggdrasil/conn.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/yggdrasil/conn.go b/src/yggdrasil/conn.go index b4f68e18..5d1e77ac 100644 --- a/src/yggdrasil/conn.go +++ b/src/yggdrasil/conn.go @@ -159,6 +159,12 @@ func (c *Conn) Read(b []byte) (int, error) { sinfo.bytesRecvd += uint64(len(b)) } // Hand over to the session worker + defer func() { + if recover() != nil { + err = errors.New("read failed, session already closed") + close(done) + } + }() // In case we're racing with a close select { // Send to worker case sinfo.worker <- workerFunc: case <-timer.C: @@ -238,7 +244,8 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) { // Hand over to the session worker defer func() { if recover() != nil { - err = errors.New("write failed") + err = errors.New("write failed, session already closed") + close(done) } }() // In case we're racing with a close select { // Send to worker