Use internal.MutexByRoom

This commit is contained in:
Neil Alexander 2021-06-28 13:59:44 +01:00
parent 6e6f026cfa
commit 138cddcac7
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -620,18 +620,13 @@ func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserv
return gomatrixserverlib.Allowed(e, &authUsingState)
}
var processEventWithMissingStateMutexes = map[string]*sync.Mutex{}
var processEventWithMissingStateMutexes = &internal.MutexByRoom{}
func (t *txnReq) processEventWithMissingState(
ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion,
) error {
mu, ok := processEventWithMissingStateMutexes[e.RoomID()]
if !ok {
processEventWithMissingStateMutexes[e.RoomID()] = &sync.Mutex{}
mu = processEventWithMissingStateMutexes[e.RoomID()]
}
mu.Lock()
defer mu.Unlock()
processEventWithMissingStateMutexes.Lock(e.RoomID())
defer processEventWithMissingStateMutexes.Unlock(e.RoomID())
// Do this with a fresh context, so that we keep working even if the
// original request times out. With any luck, by the time the remote