Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Internal server error when calling /relations with a token from /sync #14830

Closed
clokep opened this issue Jan 12, 2023 · 3 comments · Fixed by #14866
Closed

Internal server error when calling /relations with a token from /sync #14830

clokep opened this issue Jan 12, 2023 · 3 comments · Fixed by #14866
Assignees
Labels
A-Threads Threaded messages O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@clokep
Copy link
Member

clokep commented Jan 12, 2023

2023-01-12 16:41:20,025 - synapse.http.server - 124 - ERROR - GET-832933- Failed handle request via 'RelationPaginationServlet': <XForwardedForRequest at 0x7f5a7a2c98c0 method='GET' uri='/_matrix/client/v1/rooms/!test%3Amatrix.org/relations/%24foo/m.thread?dir=b&limit=20&from=sXXXX_1_YYY_ZZZ_AAA_BBB_CCC_DDD_0' clientproto='HTTP/1.1' site='8008'>
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/synapse/util/caches/descriptors.py", line 243, in _wrapped
    ret = cache.get(cache_key, callback=invalidate_callback)
  File "/usr/local/lib/python3.9/site-packages/synapse/util/caches/deferred_cache.py", line 180, in get
    raise KeyError()
KeyError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 307, in _async_render_wrapper
    callback_return = await self._async_render(request)
  File "/usr/local/lib/python3.9/site-packages/synapse/http/server.py", line 513, in _async_render
    callback_return = await raw_callback_return
  File "/usr/local/lib/python3.9/site-packages/synapse/rest/client/relations.py", line 71, in on_GET
    result = await self._relations_handler.get_relations(
  File "/usr/local/lib/python3.9/site-packages/synapse/handlers/relations.py", line 125, in get_relations
    related_events, next_token = await self._main_store.get_relations_for_event(
  File "/usr/local/lib/python3.9/site-packages/twisted/internet/defer.py", line 1697, in _inlineCallbacks
    result = context.run(gen.send, result)
  File "/usr/local/lib/python3.9/site-packages/synapse/storage/databases/main/relations.py", line 213, in get_relations_for_event
    from_token=from_token.room_key.as_historical_tuple()
  File "/usr/local/lib/python3.9/site-packages/synapse/types.py", line 569, in as_historical_tuple
    raise Exception(
Exception: Cannot call `RoomStreamToken.as_historical_tuple` on live token

https://sentry.tools.element.io/organizations/element/issues/58936/

@clokep clokep added A-Threads Threaded messages S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. O-Uncommon Most users are unlikely to come across this or unexpected workflow labels Jan 12, 2023
@clokep
Copy link
Member Author

clokep commented Jan 12, 2023

Reported by @justjanne, trying to use a token from /sync when paginating /relations, which should be allowed (df36945).

@clokep clokep changed the title 500 error in relations Internal server error when calling /relations with a token from /sync Jan 12, 2023
@clokep
Copy link
Member Author

clokep commented Jan 12, 2023

Related to #13862, I think.

@clokep clokep self-assigned this Jan 12, 2023
@clokep
Copy link
Member Author

clokep commented Jan 12, 2023

The way the pagination clause is generated is slightly incorrect, as #13862 kind of talks about. We need to abstract / port from /messages, something like this:

# The bounds for the stream tokens are complicated by the fact
# that we need to handle the instance_map part of the tokens. We do this
# by fetching all events between the min stream token and the maximum
# stream token (as returned by `RoomStreamToken.get_max_stream_pos`) and
# then filtering the results.
if from_token.topological is not None:
from_bound: Tuple[Optional[int], int] = from_token.as_historical_tuple()
elif direction == "b":
from_bound = (
None,
from_token.get_max_stream_pos(),
)
else:
from_bound = (
None,
from_token.stream,
)
to_bound: Optional[Tuple[Optional[int], int]] = None
if to_token:
if to_token.topological is not None:
to_bound = to_token.as_historical_tuple()
elif direction == "b":
to_bound = (
None,
to_token.stream,
)
else:
to_bound = (
None,
to_token.get_max_stream_pos(),
)

I have a branch that attempts to do this but is very bitrotted. I need to recreate it (or rebase it).

justjanne added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 13, 2023
justjanne added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 13, 2023
justjanne added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 13, 2023
justjanne added a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 16, 2023
…ine (#3056)

* Reset thread livetimelines when desynced
* Implement workaround for matrix-org/synapse#14830
RiotRobot pushed a commit to matrix-org/matrix-js-sdk that referenced this issue Jan 16, 2023
…ine (#3056)

* Reset thread livetimelines when desynced
* Implement workaround for matrix-org/synapse#14830

(cherry picked from commit a34d06c)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Threads Threaded messages O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Blocks non-critical functionality, workarounds exist. T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant