5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-12-23 08:45:39 +00:00

fix a panic from a doubly closed channel in the simlink

This commit is contained in:
Arceliar 2020-05-02 10:51:26 -05:00
parent 12d448f6d5
commit 15162ee952

View File

@ -14,12 +14,11 @@ type Simlink struct {
}
func (s *Simlink) readMsg() ([]byte, error) {
bs := <-s.rch
if bs != nil {
return bs, nil
} else {
bs, ok := <-s.rch
if !ok {
return nil, errors.New("read from closed Simlink")
}
return bs, nil
}
func (s *Simlink) _recvMetaBytes() ([]byte, error) {
@ -32,6 +31,7 @@ func (s *Simlink) _sendMetaBytes(bs []byte) error {
}
func (s *Simlink) close() error {
defer func() { recover() }()
close(s.rch)
return nil
}