From cbbfda3e36c2167132212ca690d0899631bc4a19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Wed, 13 Jan 2016 19:06:55 +0100 Subject: [PATCH] Recover panics in irc.Client.recv() --- irc/conn.go | 4 ++++ irc/conn_test.go | 13 +++++++++++++ 2 files changed, 17 insertions(+) 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)