Don't hold conn.mu during REGISTER. Fixes #94.

This commit is contained in:
Alex Bramley 2016-12-18 14:22:12 +00:00
parent 64ad58533d
commit 329a62d7d9
1 changed files with 12 additions and 1 deletions

View File

@ -295,6 +295,18 @@ func (conn *Conn) ConnectTo(host string, pass ...string) error {
// handler for the CONNECTED event is used to perform any initial client work
// like joining channels and sending messages.
func (conn *Conn) Connect() error {
// We don't want to hold conn.mu while firing the REGISTER event,
// and it's much easier and less error prone to defer the unlock,
// so the connect mechanics have been delegated to internalConnect.
err := conn.internalConnect()
if err == nil {
conn.dispatch(&Line{Cmd: REGISTER, Time: time.Now()})
}
return err
}
// internalConnect handles the work of actually connecting to the server.
func (conn *Conn) internalConnect() error {
conn.mu.Lock()
defer conn.mu.Unlock()
conn.initialise()
@ -350,7 +362,6 @@ func (conn *Conn) Connect() error {
conn.postConnect(true)
conn.connected = true
conn.dispatch(&Line{Cmd: REGISTER, Time: time.Now()})
return nil
}