From 6e6f026cfad31da391ad261cfec16d41dff1b15b Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 28 Jun 2021 13:50:18 +0100 Subject: [PATCH] Try to slow things down per room --- federationapi/routing/send.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index 3dd38a0d..94106141 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -620,13 +620,18 @@ func checkAllowedByState(e *gomatrixserverlib.Event, stateEvents []*gomatrixserv return gomatrixserverlib.Allowed(e, &authUsingState) } -var processEventWithMissingStateMutex sync.Mutex +var processEventWithMissingStateMutexes = map[string]*sync.Mutex{} func (t *txnReq) processEventWithMissingState( ctx context.Context, e *gomatrixserverlib.Event, roomVersion gomatrixserverlib.RoomVersion, ) error { - processEventWithMissingStateMutex.Lock() - defer processEventWithMissingStateMutex.Unlock() + mu, ok := processEventWithMissingStateMutexes[e.RoomID()] + if !ok { + processEventWithMissingStateMutexes[e.RoomID()] = &sync.Mutex{} + mu = processEventWithMissingStateMutexes[e.RoomID()] + } + mu.Lock() + defer mu.Unlock() // 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