From 899f267c479d9d3c8e36552f8a5a8bad3afc7b24 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Tue, 19 Dec 2017 11:29:49 +0000 Subject: [PATCH] Fix roomserver deadlock (#380) Move the mutex lock outside the loop so that we don't lock up if there is more than one event --- .../matrix-org/dendrite/roomserver/input/input.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/input.go b/src/github.com/matrix-org/dendrite/roomserver/input/input.go index 4d5ba5cb..4d5848f4 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/input.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/input.go @@ -61,11 +61,10 @@ func (r *RoomserverInputAPI) InputRoomEvents( request *api.InputRoomEventsRequest, response *api.InputRoomEventsResponse, ) error { + // We lock as processRoomEvent can only be called once at a time + r.mutex.Lock() + defer r.mutex.Unlock() for i := range request.InputRoomEvents { - // We lock as processRoomEvent can ony be called once at a time - r.mutex.Lock() - defer r.mutex.Unlock() - if err := processRoomEvent(ctx, r.DB, r, request.InputRoomEvents[i]); err != nil { return err }