Skip to content
This repository was archived by the owner on Nov 25, 2024. It is now read-only.

Commit 4c3a526

Browse files
authored
Fix adding state events to the database (#3133)
When we're adding state to the database, we check which eventNIDs are already in a block, if we already have that eventNID, we remove it from the list. In its current form we would skip over eventNIDs in the case we already found a match (we're decrementing `i` twice) My theory is, that when we later get the state blocks, we are receiving "too many" eventNIDs (well, yea, we stored too many), which may or may not can result in state resets when comparing different state snapshots. (e.g. when adding state we stored a eventNID by accident because we skipped it, later we add more state and are not adding it because we don't skip it)
1 parent 2ee03fd commit 4c3a526

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

roomserver/storage/shared/storage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,17 @@ func (d *Database) addState(
282282
var found bool
283283
for i := len(state) - 1; i >= 0; i-- {
284284
found = false
285+
blocksLoop:
285286
for _, events := range blocks {
286287
for _, event := range events {
287288
if state[i].EventNID == event {
288289
found = true
289-
break
290+
break blocksLoop
290291
}
291292
}
292293
}
293294
if found {
294295
state = append(state[:i], state[i+1:]...)
295-
i--
296296
}
297297
}
298298
}

0 commit comments

Comments
 (0)