Don't drain callback channel, just close it and recover
Reverts 07dbf86
, adds recovering from writing on eventually closed
channel in callback().
This commit is contained in:
parent
16e61b53a7
commit
35cd6327cf
20
rpc.go
20
rpc.go
@ -191,10 +191,14 @@ func (l *Libvirt) listen() {
|
|||||||
func (l *Libvirt) callback(id uint32, res response) {
|
func (l *Libvirt) callback(id uint32, res response) {
|
||||||
l.cm.Lock()
|
l.cm.Lock()
|
||||||
c, ok := l.callbacks[id]
|
c, ok := l.callbacks[id]
|
||||||
|
l.cm.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
|
// we close channel in deregister() so that we don't block here forever without receiver
|
||||||
|
defer func() {
|
||||||
|
recover()
|
||||||
|
}()
|
||||||
c <- res
|
c <- res
|
||||||
}
|
}
|
||||||
l.cm.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// route sends incoming packets to their listeners.
|
// route sends incoming packets to their listeners.
|
||||||
@ -281,19 +285,7 @@ func (l *Libvirt) register(id uint32, c chan response) {
|
|||||||
|
|
||||||
// deregister destroys a method response callback
|
// deregister destroys a method response callback
|
||||||
func (l *Libvirt) deregister(id uint32) {
|
func (l *Libvirt) deregister(id uint32) {
|
||||||
lockChan := make(chan bool)
|
l.cm.Lock()
|
||||||
go func() {
|
|
||||||
l.cm.Lock()
|
|
||||||
lockChan <- true
|
|
||||||
}()
|
|
||||||
Loop:
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case _ = <-l.callbacks[id]:
|
|
||||||
case _ = <-lockChan:
|
|
||||||
break Loop
|
|
||||||
}
|
|
||||||
}
|
|
||||||
close(l.callbacks[id])
|
close(l.callbacks[id])
|
||||||
delete(l.callbacks, id)
|
delete(l.callbacks, id)
|
||||||
l.cm.Unlock()
|
l.cm.Unlock()
|
||||||
|
Loading…
Reference in New Issue
Block a user