diff --git a/federationsender/queue/destinationqueue.go b/federationsender/queue/destinationqueue.go index a574950cd..45faa287c 100644 --- a/federationsender/queue/destinationqueue.go +++ b/federationsender/queue/destinationqueue.go @@ -94,8 +94,11 @@ func (oq *destinationQueue) sendInvite(ev *gomatrixserverlib.InviteV2Request) { // backgroundSend is the worker goroutine for sending events. // nolint:gocyclo func (oq *destinationQueue) backgroundSend() { - // Mark the worker as running for its lifetime. - oq.running.Store(true) + // Check if a worker is already running, and if it isn't, then + // mark it as started. + if !oq.running.CAS(false, true) { + return + } defer oq.running.Store(false) for { diff --git a/federationsender/queue/queue.go b/federationsender/queue/queue.go index 35b0bb7f0..aae6c53a0 100644 --- a/federationsender/queue/queue.go +++ b/federationsender/queue/queue.go @@ -86,7 +86,7 @@ func (oqs *OutgoingQueues) SendEvent( } // Remove our own server from the list of destinations. - destinations = filterDestinations(oqs.origin, destinations) + destinations = filterAndDedupeDests(oqs.origin, destinations) log.WithFields(log.Fields{ "destinations": destinations, "event": ev.EventID(), @@ -145,7 +145,7 @@ func (oqs *OutgoingQueues) SendEDU( } // Remove our own server from the list of destinations. - destinations = filterDestinations(oqs.origin, destinations) + destinations = filterAndDedupeDests(oqs.origin, destinations) if len(destinations) > 0 { log.WithFields(log.Fields{ @@ -160,9 +160,9 @@ func (oqs *OutgoingQueues) SendEDU( return nil } -// filterDestinations removes our own server from the list of destinations. -// Otherwise we could end up trying to talk to ourselves. -func filterDestinations(origin gomatrixserverlib.ServerName, destinations []gomatrixserverlib.ServerName) ( +// filterAndDedupeDests removes our own server from the list of destinations +// and deduplicates any servers in the list that may appear more than once. +func filterAndDedupeDests(origin gomatrixserverlib.ServerName, destinations []gomatrixserverlib.ServerName) ( result []gomatrixserverlib.ServerName, ) { strs := make([]string, len(destinations)) diff --git a/roomserver/internal/input.go b/roomserver/internal/input.go index a3a88e409..ab3d7516b 100644 --- a/roomserver/internal/input.go +++ b/roomserver/internal/input.go @@ -18,7 +18,6 @@ package internal import ( "context" "encoding/json" - "fmt" "github.com/Shopify/sarama" "github.com/matrix-org/dendrite/roomserver/api" @@ -68,7 +67,6 @@ func (r *RoomserverInternalAPI) InputRoomEvents( // loopback room event containing the invite, for local invites. // If it does, we should process it with the room events below. if loopback != nil { - fmt.Println("LOOPING BACK", string(loopback.Event.JSON())) request.InputRoomEvents = append(request.InputRoomEvents, *loopback) } }