diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2020-11-18 11:31:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-18 11:31:58 +0000 |
commit | 265cf5e835575b69575b209e4b1ad2be2016b396 (patch) | |
tree | 46be981c187d7b9f1a042292df71e7e3ada77466 /federationapi | |
parent | 3bcb00324851bf85c8659893131c4a515ff19638 (diff) |
Protect txnReq.newEvents with mutex (#1587)
* Protect txnReq.newEvents and txnReq.haveEvents with mutex
* Missing defer
* Remove t.haveEventsMutex
Diffstat (limited to 'federationapi')
-rw-r--r-- | federationapi/routing/send.go | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 104d2e73..a3011b50 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -111,7 +111,8 @@ type txnReq struct { // which the roomserver is unaware of. haveEvents map[string]*gomatrixserverlib.HeaderedEvent // 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. @@ -264,6 +265,8 @@ func (e missingPrevEventsError) Error() string { } func (t *txnReq) haveEventIDs() map[string]bool { + t.newEventsMutex.RLock() + defer t.newEventsMutex.RUnlock() result := make(map[string]bool, len(t.haveEvents)) for eventID := range t.haveEvents { if t.newEvents[eventID] { @@ -1144,6 +1147,8 @@ func (t *txnReq) lookupEvent(ctx context.Context, roomVersion gomatrixserverlib. return nil, verifySigError{event.EventID(), err} } h := event.Headered(roomVersion) + t.newEventsMutex.Lock() t.newEvents[h.EventID()] = true + t.newEventsMutex.Unlock() return h, nil } |