mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-03 08:28:31 +00:00
Attempt to fix locking issue
This commit is contained in:
parent
db486e4eba
commit
7b095542fc
3 changed files with 11 additions and 2 deletions
|
@ -431,7 +431,10 @@ func HandleBunchedRemoteCommand(conn *websocket.Conn, client *ClientInfo, msg Cl
|
|||
bsl.Lock()
|
||||
for _, member := range bsl.Members {
|
||||
msg.MessageID = member.MessageID
|
||||
member.Client.MessageChannel <- msg
|
||||
select {
|
||||
case member.Client.MessageChannel <- msg:
|
||||
case <-member.Client.MsgChannelIsDone:
|
||||
}
|
||||
member.Client.MsgChannelKeepalive.Done()
|
||||
}
|
||||
bsl.Unlock()
|
||||
|
|
|
@ -152,6 +152,7 @@ func HandleSocketConnection(conn *websocket.Conn) {
|
|||
var client ClientInfo
|
||||
client.MessageChannel = _serverMessageChan
|
||||
client.RemoteAddr = conn.RemoteAddr()
|
||||
client.MsgChannelIsDone = stoppedChan
|
||||
|
||||
// Launch receiver goroutine
|
||||
go func(errorChan chan<- error, clientChan chan<- ClientMessage, stoppedChan <-chan struct{}) {
|
||||
|
@ -186,7 +187,10 @@ func HandleSocketConnection(conn *websocket.Conn) {
|
|||
if err != io.EOF && !isClose {
|
||||
log.Println("Error while reading from client:", err)
|
||||
}
|
||||
errorChan <- err
|
||||
select {
|
||||
case errorChan <- err:
|
||||
case <-stoppedChan:
|
||||
}
|
||||
close(errorChan)
|
||||
close(clientChan)
|
||||
// exit
|
||||
|
|
|
@ -91,6 +91,8 @@ type ClientInfo struct {
|
|||
// This field will be nil before it is closed.
|
||||
MessageChannel chan<- ClientMessage
|
||||
|
||||
MsgChannelIsDone <-chan struct{}
|
||||
|
||||
// Take out an Add() on this during a command if you need to use the MessageChannel later.
|
||||
MsgChannelKeepalive sync.WaitGroup
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue