From 9f74a8798e26d9482f1964ff79a28acfe61d6dd1 Mon Sep 17 00:00:00 2001 From: Kegsay Date: Mon, 16 Mar 2020 17:51:58 +0000 Subject: [PATCH] bugfix: Fix #908 by setting the correct state after the event (#913) * bugfix: Fix #908 by setting the correct state after the event Previously, this would only happen if the state already existed previously! * Structured logging --- federationapi/routing/send.go | 1 + roomserver/state/v1/state.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/federationapi/routing/send.go b/federationapi/routing/send.go index ce9ad8b13..d3e060ac2 100644 --- a/federationapi/routing/send.go +++ b/federationapi/routing/send.go @@ -116,6 +116,7 @@ func (t *txnReq) processTransaction() (*gomatrixserverlib.RespSend, error) { results[e.EventID()] = gomatrixserverlib.PDUResult{ Error: err.Error(), } + util.GetLogger(t.context).WithError(err).WithField("event_id", e.EventID()).Warn("Failed to process incoming federation event, skipping it.") } else { results[e.EventID()] = gomatrixserverlib.PDUResult{} } diff --git a/roomserver/state/v1/state.go b/roomserver/state/v1/state.go index 5683745bf..3eb601925 100644 --- a/roomserver/state/v1/state.go +++ b/roomserver/state/v1/state.go @@ -366,11 +366,16 @@ func (v StateResolutionV1) loadStateAfterEventsForNumericTuples( // update that key in the result. // If the requested event wasn't a state event then the state after // it is the same as the state before it. + set := false for i := range result { if result[i].StateKeyTuple == prevState.StateKeyTuple { result[i] = prevState.StateEntry + set = true } } + if !set { // no previous state exists for this event: add new state + result = append(result, prevState.StateEntry) + } } return result, nil }