-
Notifications
You must be signed in to change notification settings - Fork 69
Guard against homeservers stuck in a /messages pagination loop
#903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -427,7 +427,18 @@ func _sendAndTestMessageHistory( | |||||||||||||||||
| testCase.numberOfMessagesToSend, | ||||||||||||||||||
| ) | ||||||||||||||||||
| fromToken := "" | ||||||||||||||||||
| for { | ||||||||||||||||||
| // Guard against a buggy homeserver that never terminates pagination (e.g. it | ||||||||||||||||||
| // keeps returning an `end` token, possibly oscillating between a small set of | ||||||||||||||||||
| // tokens like `[-1, 1]` -> `[1, -1]` -> ...). Without this, the test would spin | ||||||||||||||||||
| // until the overall test timeout (which can be as long as 3600s) instead of | ||||||||||||||||||
| // failing fast with a useful error. | ||||||||||||||||||
| seenTokens := map[string]bool{fromToken: true} | ||||||||||||||||||
| maxIterations := testCase.numberOfMessagesToSend + 1 | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| for iteration := 0; ; iteration++ { | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| if iteration >= maxIterations { | ||||||||||||||||||
| t.Fatalf("paginated %d times without reaching the start of the room (no `end` token) -- homeserver may be stuck in a pagination loop", iteration) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
| } | ||||||||||||||||||
|
Comment on lines
+436
to
+440
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Having |
||||||||||||||||||
|
|
||||||||||||||||||
| messageQueryParams := url.Values{ | ||||||||||||||||||
| "dir": []string{"b"}, | ||||||||||||||||||
| "limit": []string{strconv.Itoa(testCase.messagesRequestLimit)}, | ||||||||||||||||||
|
|
@@ -472,6 +483,11 @@ func _sendAndTestMessageHistory( | |||||||||||||||||
| break | ||||||||||||||||||
| } | ||||||||||||||||||
| fromToken = endTokenRes.Str | ||||||||||||||||||
|
|
||||||||||||||||||
| if seenTokens[fromToken] { | ||||||||||||||||||
| t.Fatalf("homeserver returned a pagination token (%s) we've already seen -- it appears to be stuck in loop or repeating elements", fromToken) | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's valid for a homeserver to return the same pagination token if it doesn't have anything to return yet (still backfilling). (we should get rid of this check) |
||||||||||||||||||
| } | ||||||||||||||||||
| seenTokens[fromToken] = true | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| // Put them in chronological order to match the expected list | ||||||||||||||||||
|
|
||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.