Attempt to fix the orphan client issue.
This commit is contained in:
parent
7a9ec1a1d3
commit
04d4e0fc6a
10
main.go
10
main.go
|
@ -168,6 +168,7 @@ func broadcastFiber(name string) {
|
||||||
e := ctx.clientsChanList.Front()
|
e := ctx.clientsChanList.Front()
|
||||||
for e != nil {
|
for e != nil {
|
||||||
ch := e.Value.(*ClientChannel)
|
ch := e.Value.(*ClientChannel)
|
||||||
|
// Note: select in Golang is not ordered!
|
||||||
select {
|
select {
|
||||||
case <-ch.Notify:
|
case <-ch.Notify:
|
||||||
// Closed client, remove this entry
|
// Closed client, remove this entry
|
||||||
|
@ -175,11 +176,14 @@ func broadcastFiber(name string) {
|
||||||
next := e.Next()
|
next := e.Next()
|
||||||
ctx.clientsChanList.Remove(e)
|
ctx.clientsChanList.Remove(e)
|
||||||
e = next
|
e = next
|
||||||
case ch.Data <- chunk:
|
break
|
||||||
e = e.Next()
|
|
||||||
default:
|
default:
|
||||||
e = e.Next()
|
|
||||||
}
|
}
|
||||||
|
select {
|
||||||
|
case ch.Data <- chunk:
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
e = e.Next()
|
||||||
}
|
}
|
||||||
// Try to serve all new clients, but don't get locked up here :)
|
// Try to serve all new clients, but don't get locked up here :)
|
||||||
if ctx.newClientsChanList.Len() > 0 && ctx.newChanLock.TryLock() {
|
if ctx.newClientsChanList.Len() > 0 && ctx.newChanLock.TryLock() {
|
||||||
|
|
Loading…
Reference in New Issue