From 13c8c61d28a6d611c383003bd7e1bb8b5ccb262b Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Fri, 16 Aug 2019 11:10:22 -0500 Subject: [PATCH 1/2] conn: On Close, leave all rooms, and call the disconnect handler --- conn.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/conn.go b/conn.go index 1064e46a..87b0d770 100644 --- a/conn.go +++ b/conn.go @@ -84,6 +84,11 @@ func newConn(c engineio.Conn, handlers map[string]*namespaceHandler, broadcast B func (c *conn) Close() error { var err error c.closeOnce.Do(func() { + // For each namespace, leave all rooms, and call the disconnect handler. + for ns, nc := range c.namespaces { + nc.LeaveAll() + c.handlers[ns].onDisconnect(nc, "bye") + } err = c.Conn.Close() close(c.quitChan) }) From 90e10dea5dba944012a799508581c6074c4c345b Mon Sep 17 00:00:00 2001 From: Jonathan Chappelow Date: Sat, 17 Aug 2019 10:21:29 -0500 Subject: [PATCH 2/2] Ensure the corresponding `namespaceHandler` exists. --- conn.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/conn.go b/conn.go index 87b0d770..6e0cc102 100644 --- a/conn.go +++ b/conn.go @@ -87,7 +87,9 @@ func (c *conn) Close() error { // For each namespace, leave all rooms, and call the disconnect handler. for ns, nc := range c.namespaces { nc.LeaveAll() - c.handlers[ns].onDisconnect(nc, "bye") + if nh := c.handlers[ns]; nh != nil { + nh.onDisconnect(nc, "bye") + } } err = c.Conn.Close() close(c.quitChan)