From b58c9bb094f3a069a4f40bbd6cc4a0ac205afcb6 Mon Sep 17 00:00:00 2001 From: devonh Date: Thu, 20 Oct 2022 15:37:35 +0000 Subject: [PATCH 1/2] Fix flakey queue test (#2818) Ensure both events are added to the database, even if the destination is already blacklisted. --- federationapi/queue/queue_test.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/federationapi/queue/queue_test.go b/federationapi/queue/queue_test.go index 6da9e6b30..40419b91f 100644 --- a/federationapi/queue/queue_test.go +++ b/federationapi/queue/queue_test.go @@ -1004,9 +1004,12 @@ func TestQueueInteractsWithRealDatabasePDUAndEDU(t *testing.T) { err := queues.SendEvent(ev, "localhost", []gomatrixserverlib.ServerName{destination}) assert.NoError(t, err) + // NOTE : The server can be blacklisted before this, so manually inject the event + // into the database. edu := mustCreateEDU(t) - errEDU := queues.SendEDU(edu, "localhost", []gomatrixserverlib.ServerName{destination}) - assert.NoError(t, errEDU) + ephemeralJSON, _ := json.Marshal(edu) + nid, _ := db.StoreJSON(pc.Context(), string(ephemeralJSON)) + db.AssociateEDUWithDestination(pc.Context(), destination, nid, edu.Type, nil) checkBlacklisted := func(log poll.LogT) poll.Result { if fc.txCount.Load() == failuresUntilBlacklist { From 90414912012b274f49894b2819f5e6e393928da9 Mon Sep 17 00:00:00 2001 From: devonh Date: Thu, 20 Oct 2022 15:54:18 +0000 Subject: [PATCH 2/2] Mutex protect query keys response (#2812) --- keyserver/internal/internal.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/keyserver/internal/internal.go b/keyserver/internal/internal.go index 89621aa87..49ef03054 100644 --- a/keyserver/internal/internal.go +++ b/keyserver/internal/internal.go @@ -472,7 +472,9 @@ func (a *KeyInternalAPI) queryRemoteKeys( close(resultCh) }() - for result := range resultCh { + processResult := func(result *gomatrixserverlib.RespQueryKeys) { + respMu.Lock() + defer respMu.Unlock() for userID, nest := range result.DeviceKeys { res.DeviceKeys[userID] = make(map[string]json.RawMessage) for deviceID, deviceKey := range nest { @@ -495,6 +497,10 @@ func (a *KeyInternalAPI) queryRemoteKeys( // TODO: do we want to persist these somewhere now // that we have fetched them? } + + for result := range resultCh { + processResult(result) + } } func (a *KeyInternalAPI) queryRemoteKeysOnServer(