diff --git a/irc/conn.go b/irc/conn.go index 043e4e7b..a61da629 100644 --- a/irc/conn.go +++ b/irc/conn.go @@ -146,6 +146,10 @@ func (c *Client) send() { } func (c *Client) recv() { + defer func() { + recover() + }() + c.sendRecv.Add(1) defer c.sendRecv.Done() diff --git a/irc/conn_test.go b/irc/conn_test.go index 7769c74b..a25582ef 100644 --- a/irc/conn_test.go +++ b/irc/conn_test.go @@ -132,6 +132,19 @@ func TestRecv(t *testing.T) { initTestClient() } +func TestRecvRecoversPanic(t *testing.T) { + defer func() { + assert.Nil(t, recover()) + }() + + buf := bytes.NewBuffer([]byte("CMD\r\n")) + c.reader = bufio.NewReader(buf) + close(c.Messages) + c.recv() + + c.Messages = make(chan *Message, 32) +} + /*func TestRecvTriggersReconnect(t *testing.T) { c.reader = bufio.NewReader(&bytes.Buffer{}) c.ready.Add(1)