mirror of https://github.com/fluffle/goirc
client/connection: fix deadlock with double shutdown
This commit is contained in:
parent
0cac69d2ee
commit
19815ba792
|
@ -4,13 +4,14 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/fluffle/goirc/logging"
|
|
||||||
"github.com/fluffle/goirc/state"
|
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/fluffle/goirc/logging"
|
||||||
|
"github.com/fluffle/goirc/state"
|
||||||
)
|
)
|
||||||
|
|
||||||
// An IRC connection is represented by this struct.
|
// An IRC connection is represented by this struct.
|
||||||
|
@ -404,7 +405,6 @@ func (conn *Conn) shutdown() {
|
||||||
// Guard against double-call of shutdown() if we get an error in send()
|
// 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()
|
// as calling sock.Close() will cause recv() to receive EOF in readstring()
|
||||||
conn.mu.Lock()
|
conn.mu.Lock()
|
||||||
defer conn.mu.Unlock()
|
|
||||||
if !conn.connected {
|
if !conn.connected {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -412,6 +412,8 @@ func (conn *Conn) shutdown() {
|
||||||
conn.connected = false
|
conn.connected = false
|
||||||
conn.sock.Close()
|
conn.sock.Close()
|
||||||
close(conn.die)
|
close(conn.die)
|
||||||
|
// Unlock before waiting, https://github.com/StalkR/goircbot/issues/11
|
||||||
|
conn.mu.Unlock()
|
||||||
conn.wg.Wait()
|
conn.wg.Wait()
|
||||||
// Dispatch after closing connection but before reinit
|
// Dispatch after closing connection but before reinit
|
||||||
// so event handlers can still access state information.
|
// so event handlers can still access state information.
|
||||||
|
|
Loading…
Reference in New Issue