mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-29 21:21:35 +00:00
fix another panic from a send on a closed session worker channel, from races between Conn.Read/Write/Close
This commit is contained in:
parent
cd29fde178
commit
86c30a1fc4
@ -159,6 +159,12 @@ func (c *Conn) Read(b []byte) (int, error) {
|
|||||||
sinfo.bytesRecvd += uint64(len(b))
|
sinfo.bytesRecvd += uint64(len(b))
|
||||||
}
|
}
|
||||||
// Hand over to the session worker
|
// 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
|
select { // Send to worker
|
||||||
case sinfo.worker <- workerFunc:
|
case sinfo.worker <- workerFunc:
|
||||||
case <-timer.C:
|
case <-timer.C:
|
||||||
@ -238,7 +244,8 @@ func (c *Conn) Write(b []byte) (bytesWritten int, err error) {
|
|||||||
// Hand over to the session worker
|
// Hand over to the session worker
|
||||||
defer func() {
|
defer func() {
|
||||||
if recover() != nil {
|
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
|
}() // In case we're racing with a close
|
||||||
select { // Send to worker
|
select { // Send to worker
|
||||||
|
Loading…
Reference in New Issue
Block a user