mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
fix a race
This commit is contained in:
parent
213afc0481
commit
0f6ee63e6e
@ -51,12 +51,14 @@ func NewChannel(s *Server, name string) *Channel {
|
||||
}
|
||||
|
||||
func (channel *Channel) Destroy() {
|
||||
if channel.destroyed {
|
||||
if channel.IsDestroyed() {
|
||||
return
|
||||
}
|
||||
|
||||
channel.withMutex(func() {
|
||||
channel.destroyed = true
|
||||
channel.members = make(ClientSet)
|
||||
})
|
||||
channel.server.channels.Remove(channel)
|
||||
}
|
||||
|
||||
@ -70,7 +72,7 @@ func (channel *Channel) Reply(reply Reply) {
|
||||
|
||||
func (channel *Channel) receiveCommands(commands <-chan ChannelCommand) {
|
||||
for command := range commands {
|
||||
if channel.destroyed {
|
||||
if channel.IsDestroyed() {
|
||||
if DEBUG_CHANNEL {
|
||||
log.Printf("%s → %s %s dropped", command.Source(), channel, command)
|
||||
}
|
||||
@ -92,9 +94,15 @@ func IsPrivMsg(reply Reply) bool {
|
||||
return strReply.code == "PRIVMSG"
|
||||
}
|
||||
|
||||
func (channel *Channel) IsDestroyed() bool {
|
||||
channel.mutex.Lock()
|
||||
defer channel.mutex.Unlock()
|
||||
return channel.destroyed
|
||||
}
|
||||
|
||||
func (channel *Channel) receiveReplies(replies <-chan Reply) {
|
||||
for reply := range replies {
|
||||
if channel.destroyed {
|
||||
if channel.IsDestroyed() {
|
||||
if DEBUG_CHANNEL {
|
||||
log.Printf("%s ← %s %s dropped", channel, reply.Source(), reply)
|
||||
}
|
||||
|
@ -364,12 +364,14 @@ func (m *JoinCommand) HandleServer(s *Server) {
|
||||
}
|
||||
}
|
||||
|
||||
func (m *PartCommand) HandleServer(s *Server) {
|
||||
func (m *PartCommand) HandleServer(server *Server) {
|
||||
for _, chname := range m.channels {
|
||||
channel := s.channels[chname]
|
||||
server.mutex.Lock()
|
||||
channel := server.channels[chname]
|
||||
server.mutex.Unlock()
|
||||
|
||||
if channel == nil {
|
||||
m.Client().Reply(ErrNoSuchChannel(s, channel.name))
|
||||
m.Client().Reply(ErrNoSuchChannel(server, channel.name))
|
||||
continue
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user