fix: Lock sessionListMutex in BroadcastLine()
This commit is contained in:
parent
2dd8f72714
commit
8538df7a14
1 changed files with 4 additions and 3 deletions
7
ssh.go
7
ssh.go
|
@ -70,9 +70,10 @@ func RemoveFromSessionList(idx int) {
|
|||
|
||||
func BroadcastLine(line []byte) {
|
||||
if logFlag { log.Printf("%s", line) } // output message
|
||||
sessions := sessionList // create snapshot of client list
|
||||
for i := range(len(sessions)) {
|
||||
session := sessions[i]
|
||||
sessionListMutex.Lock()
|
||||
defer sessionListMutex.Unlock()
|
||||
for i := range(len(sessionList)) {
|
||||
session := sessionList[i]
|
||||
if session != nil {
|
||||
(*session).Write(line)
|
||||
}
|
||||
|
|
Reference in a new issue