mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	fix a panic from a doubly closed channel in the simlink
This commit is contained in:
		
							parent
							
								
									12d448f6d5
								
							
						
					
					
						commit
						15162ee952
					
				
					 1 changed files with 4 additions and 4 deletions
				
			
		| 
						 | 
					@ -14,12 +14,11 @@ type Simlink struct {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Simlink) readMsg() ([]byte, error) {
 | 
					func (s *Simlink) readMsg() ([]byte, error) {
 | 
				
			||||||
	bs := <-s.rch
 | 
						bs, ok := <-s.rch
 | 
				
			||||||
	if bs != nil {
 | 
						if !ok {
 | 
				
			||||||
		return bs, nil
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		return nil, errors.New("read from closed Simlink")
 | 
							return nil, errors.New("read from closed Simlink")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						return bs, nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Simlink) _recvMetaBytes() ([]byte, error) {
 | 
					func (s *Simlink) _recvMetaBytes() ([]byte, error) {
 | 
				
			||||||
| 
						 | 
					@ -32,6 +31,7 @@ func (s *Simlink) _sendMetaBytes(bs []byte) error {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *Simlink) close() error {
 | 
					func (s *Simlink) close() error {
 | 
				
			||||||
 | 
						defer func() { recover() }()
 | 
				
			||||||
	close(s.rch)
 | 
						close(s.rch)
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue