From f12a174523632477faff7efdf453e21d78e480f9 Mon Sep 17 00:00:00 2001 From: Alex Bramley Date: Tue, 14 Apr 2015 07:50:39 +0100 Subject: [PATCH] Only dispatch DISCONNECTED once. --- client/connection.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/connection.go b/client/connection.go index 852db07..511b157 100644 --- a/client/connection.go +++ b/client/connection.go @@ -401,14 +401,11 @@ func (conn *Conn) rateLimit(chars int) time.Duration { } func (conn *Conn) shutdown() { - // Dispatch after closing connection but before reinit - // so event handlers can still access state information. - defer conn.dispatch(&Line{Cmd: DISCONNECTED, Time: time.Now()}) // Guard against double-call of shutdown() if we get an error in send() // as calling sock.Close() will cause recv() to receive EOF in readstring() conn.mu.Lock() - defer conn.mu.Unlock() if !conn.connected { + conn.mu.Unlock() return } logging.Info("irc.shutdown(): Disconnected from server.") @@ -416,6 +413,10 @@ func (conn *Conn) shutdown() { conn.sock.Close() close(conn.die) conn.wg.Wait() + conn.mu.Unlock() + // Dispatch after closing connection but before reinit + // so event handlers can still access state information. + defer conn.dispatch(&Line{Cmd: DISCONNECTED, Time: time.Now()}) } // Dumps a load of information about the current state of the connection to a