diff --git a/session.go b/session.go index 0912bce..da7b875 100644 --- a/session.go +++ b/session.go @@ -59,12 +59,19 @@ func (s *localPeer) Receive() <-chan Message { return s.incoming } -func (s *localPeer) Send(msg Message) error { +func (s *localPeer) Send(msg Message) (err error) { + defer func() { + // just in case Close is called before Send + err = recover() + }() s.outgoing <- msg - return nil + return } func (s *localPeer) Close() error { - close(s.outgoing) + if s.outgoing != nil { + close(s.outgoing) + s.outgoing = nil + } return nil }