From de168addd5bb6e24a6ed2ac7bd6038fa3a1c15bf Mon Sep 17 00:00:00 2001 From: Marten Seemann Date: Thu, 1 Dec 2016 16:33:54 +0700 Subject: [PATCH] =?UTF-8?q?don=E2=80=99t=20panic=20after=20sending=20a=20C?= =?UTF-8?q?onnectionClose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client.go | 8 ++++++-- example/client/client.go | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index 16cdc897b..5e1d2f519 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "math/rand" "net" "net/url" + "strings" "time" "github.com/lucas-clemente/quic-go/protocol" @@ -73,7 +74,7 @@ func NewClient(addr string) (*Client, error) { } // Listen listens -func (c *Client) Listen() { +func (c *Client) Listen() error { go c.session.run() for { @@ -82,7 +83,10 @@ func (c *Client) Listen() { n, _, err := c.conn.ReadFromUDP(data) if err != nil { - panic(err) + if strings.HasSuffix(err.Error(), "use of closed network connection") { + return nil + } + return err } data = data[:n] diff --git a/example/client/client.go b/example/client/client.go index 0925033e3..24b03dbd9 100644 --- a/example/client/client.go +++ b/example/client/client.go @@ -15,5 +15,8 @@ func main() { panic(err) } - client.Listen() + err = client.Listen() + if err != nil { + panic(err) + } }