Protect txnReq.newEvents with mutex (#1587)
* Protect txnReq.newEvents and txnReq.haveEvents with mutex * Missing defer * Remove t.haveEventsMutexmain
parent
3bcb003248
commit
265cf5e835
|
@ -112,6 +112,7 @@ type txnReq struct {
|
||||||
haveEvents map[string]*gomatrixserverlib.HeaderedEvent
|
haveEvents map[string]*gomatrixserverlib.HeaderedEvent
|
||||||
// new events which the roomserver does not know about
|
// new events which the roomserver does not know about
|
||||||
newEvents map[string]bool
|
newEvents map[string]bool
|
||||||
|
newEventsMutex sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// A subset of FederationClient functionality that txn requires. Useful for testing.
|
// A subset of FederationClient functionality that txn requires. Useful for testing.
|
||||||
|
@ -264,6 +265,8 @@ func (e missingPrevEventsError) Error() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *txnReq) haveEventIDs() map[string]bool {
|
func (t *txnReq) haveEventIDs() map[string]bool {
|
||||||
|
t.newEventsMutex.RLock()
|
||||||
|
defer t.newEventsMutex.RUnlock()
|
||||||
result := make(map[string]bool, len(t.haveEvents))
|
result := make(map[string]bool, len(t.haveEvents))
|
||||||
for eventID := range t.haveEvents {
|
for eventID := range t.haveEvents {
|
||||||
if t.newEvents[eventID] {
|
if t.newEvents[eventID] {
|
||||||
|
@ -1144,6 +1147,8 @@ func (t *txnReq) lookupEvent(ctx context.Context, roomVersion gomatrixserverlib.
|
||||||
return nil, verifySigError{event.EventID(), err}
|
return nil, verifySigError{event.EventID(), err}
|
||||||
}
|
}
|
||||||
h := event.Headered(roomVersion)
|
h := event.Headered(roomVersion)
|
||||||
|
t.newEventsMutex.Lock()
|
||||||
t.newEvents[h.EventID()] = true
|
t.newEvents[h.EventID()] = true
|
||||||
|
t.newEventsMutex.Unlock()
|
||||||
return h, nil
|
return h, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue