mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-22 11:59:40 +01:00
fix double-destroy bug
This commit is contained in:
parent
74732c4aeb
commit
1a7169d75d
@ -53,6 +53,7 @@ type Client struct {
|
|||||||
certfp string
|
certfp string
|
||||||
channels ChannelSet
|
channels ChannelSet
|
||||||
ctime time.Time
|
ctime time.Time
|
||||||
|
destroyed bool
|
||||||
exitedSnomaskSent bool
|
exitedSnomaskSent bool
|
||||||
flags modes.ModeSet
|
flags modes.ModeSet
|
||||||
hostname string
|
hostname string
|
||||||
@ -962,7 +963,6 @@ func (client *Client) Quit(message string, session *Session) {
|
|||||||
func (client *Client) destroy(session *Session) {
|
func (client *Client) destroy(session *Session) {
|
||||||
var sessionsToDestroy []*Session
|
var sessionsToDestroy []*Session
|
||||||
|
|
||||||
// allow destroy() to execute at most once
|
|
||||||
client.stateMutex.Lock()
|
client.stateMutex.Lock()
|
||||||
details := client.detailsNoMutex()
|
details := client.detailsNoMutex()
|
||||||
brbState := client.brbTimer.state
|
brbState := client.brbTimer.state
|
||||||
@ -980,6 +980,13 @@ func (client *Client) destroy(session *Session) {
|
|||||||
sessionsToDestroy = []*Session{session}
|
sessionsToDestroy = []*Session{session}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// should we destroy the whole client this time?
|
||||||
|
shouldDestroy := !client.destroyed && remainingSessions == 0 && (brbState != BrbEnabled && brbState != BrbSticky)
|
||||||
|
if shouldDestroy {
|
||||||
|
// if it's our job to destroy it, don't let anyone else try
|
||||||
|
client.destroyed = true
|
||||||
|
}
|
||||||
client.stateMutex.Unlock()
|
client.stateMutex.Unlock()
|
||||||
|
|
||||||
// destroy all applicable sessions:
|
// destroy all applicable sessions:
|
||||||
@ -1013,8 +1020,7 @@ func (client *Client) destroy(session *Session) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// do not destroy the client if it has either remaining sessions, or is BRB'ed
|
// do not destroy the client if it has either remaining sessions, or is BRB'ed
|
||||||
if remainingSessions != 0 || brbState == BrbEnabled || brbState == BrbSticky {
|
if !shouldDestroy {
|
||||||
client.server.logger.Debug("quit", fmt.Sprintf("preserving client %s with %d remaining sessions\n", details.nick, remainingSessions))
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user