Fix concurrent map writes in presence queue
This commit is contained in:
parent
540c6cd546
commit
f052d633ac
|
@ -90,7 +90,9 @@ func heartbeat(component *xmpp.Component) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
gateway.LogBadPresence(presence)
|
gateway.LogBadPresence(presence)
|
||||||
} else {
|
} else {
|
||||||
|
gateway.QueueLock.Lock()
|
||||||
delete(gateway.Queue, key)
|
delete(gateway.Queue, key)
|
||||||
|
gateway.QueueLock.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package gateway
|
||||||
import (
|
import (
|
||||||
"encoding/xml"
|
"encoding/xml"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"dev.narayana.im/narayana/telegabber/xmpp/extensions"
|
"dev.narayana.im/narayana/telegabber/xmpp/extensions"
|
||||||
|
|
||||||
|
@ -14,6 +15,7 @@ import (
|
||||||
|
|
||||||
// Queue stores presences to send later
|
// Queue stores presences to send later
|
||||||
var Queue = make(map[string]*stanza.Presence)
|
var Queue = make(map[string]*stanza.Presence)
|
||||||
|
var QueueLock = sync.Mutex{}
|
||||||
|
|
||||||
// Jid stores the component's JID object
|
// Jid stores the component's JID object
|
||||||
var Jid *stanza.Jid
|
var Jid *stanza.Jid
|
||||||
|
@ -178,7 +180,9 @@ func SendPresence(component *xmpp.Component, to string, args ...args.V) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
QueueLock.Lock()
|
||||||
Queue[presence.From+presence.To] = &presence
|
Queue[presence.From+presence.To] = &presence
|
||||||
|
QueueLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue