# HG changeset patch # User Chris Jones # Date 1381976969 21600 # Node ID f4ccc2f297771e9a637c2c941302bf5bf2258a4d # Parent 7ce61108ed86d91cccf12cc840bc1ac1bf0c7f3a Don't call Close() twice. diff -r 7ce61108ed86 -r f4ccc2f29777 xmpp/xmpp.go --- a/xmpp/xmpp.go Wed Oct 16 20:05:02 2013 -0600 +++ b/xmpp/xmpp.go Wed Oct 16 20:29:29 2013 -0600 @@ -13,6 +13,7 @@ "io" "net" "reflect" + "sync" ) const ( @@ -80,6 +81,7 @@ tlsConfig tls.Config layer1 *layer1 error chan error + shutdownOnce sync.Once } // Creates an XMPP client identified by the given JID, authenticating @@ -249,8 +251,11 @@ // there's already an error in the channel, discard the newer one in // favor of the older. func (cl *Client) setError(err error) { - defer cl.Close() - defer cl.setStatus(StatusError) + shutdown := func() { + cl.setStatus(StatusError) + cl.Close() + } + defer cl.shutdownOnce.Do(shutdown) if len(cl.error) > 0 { return