From 138cddcac7b8373a8e1816a232f84a7bda6adcdf Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 28 Jun 2021 13:59:44 +0100 Subject: [PATCH] Use internal.MutexByRoom --- federationapi/routing/send.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 94106141..97425f52 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -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