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) {
|
func BroadcastLine(line []byte) {
|
||||||
if logFlag { log.Printf("%s", line) } // output message
|
if logFlag { log.Printf("%s", line) } // output message
|
||||||
sessions := sessionList // create snapshot of client list
|
sessionListMutex.Lock()
|
||||||
for i := range(len(sessions)) {
|
defer sessionListMutex.Unlock()
|
||||||
session := sessions[i]
|
for i := range(len(sessionList)) {
|
||||||
|
session := sessionList[i]
|
||||||
if session != nil {
|
if session != nil {
|
||||||
(*session).Write(line)
|
(*session).Write(line)
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue