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

Incremental /sync and /transactions query events differently #11394

Open
MadLittleMods opened this issue Nov 18, 2021 · 1 comment
Open

Incremental /sync and /transactions query events differently #11394

MadLittleMods opened this issue Nov 18, 2021 · 1 comment
Labels
A-Application-Service Related to AS support A-Sync defects related to /sync T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.

Comments

@MadLittleMods
Copy link
Contributor

MadLittleMods commented Nov 18, 2021

As discovered in #11265 (comment)


/sync looks for stream_ordering but excludes all outliers.

sql = """
SELECT event_id, instance_name, topological_ordering, stream_ordering
FROM events
WHERE
room_id = ?
AND not outlier
AND stream_ordering > ? AND stream_ordering <= ?
ORDER BY stream_ordering %s LIMIT ?
""" % (

Whereas /transactions(Application service API) only cares about stream_ordering.

def get_new_events_for_appservice_txn(txn):
sql = (
"SELECT e.stream_ordering, e.event_id"
" FROM events AS e"
" WHERE"
" (SELECT stream_ordering FROM appservice_stream_position)"
" < e.stream_ordering"
" AND e.stream_ordering <= ?"
" ORDER BY e.stream_ordering ASC"
" LIMIT ?"
)

The behavior of these two endpoints should probably return and push the same events.

Here is the history behind why we added AND not outlier to the incremental sync endpoint, "Don't return outliers when we get recent events for rooms.", 1505055 but it doesn't explain the why or which interaction creates outlier events that aren't backfilled.

What does the spec say?

For /transactions, the spec doesn't distinguish which events a homeserver should and shouldn't push, https://spec.matrix.org/v1.1/application-service-api/#put_matrixappv1transactionstxnid

For /sync, there is also nothing so clear cut but it's obvious using the since pagination query parameter that it should return anything after which equates to stream_ordering in Synapse land.

Potential solutions

Exclude outliers in both

Perhaps we should exclude outliers in /transactions so they both just match?

@richvdh had some critique about this approach though:

the outlier flag seems like a poor way to decide whether we should push this data. (Yes, outliers shouldn't be sent over /transactions, but there are probably many other events which shouldn't be sent).

FederationEventHandler._process_received_pdu has a backfilled parameter (see synapse/handlers/federation_event.py#L945), whose purpose is slightly unclear, but I think one of its jobs is this sort of thing. Maybe we should use similar logic to that, somehow?

-- @richvdh, https://github.com/matrix-org/synapse/pull/11265#discussion_r746523400

But for /transactions, we can't tell whether the event was backfilled. The only indication is that the stream_ordering would be negative which is what the /transactions code already takes into account.

Only exclude backfilled events

This means only relying on stream_ordering.

Then any interaction creating outliers that we don't want to appear down /sync//transactions, should be updated to be also marked as backfilled.

Dev notes

/sync stack trace

/transactions stack trace

submit_event_for_as ->

@MadLittleMods MadLittleMods added A-Application-Service Related to AS support A-Sync defects related to /sync T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. labels Nov 18, 2021
@MadLittleMods MadLittleMods changed the title Incremental /sync and `/transactions query events differently Incremental /sync and /transactions query events differently Nov 18, 2021
@MadLittleMods
Copy link
Contributor Author

Spawning from a discussion with the Rocket.chat folks,

One point against excluding outliers from both; currently when we persist inbound invites over federation, they are set as outliers (related #8626). And since we don't exclude outliers when pushing out events for application service /transactions, the AS can still pick up the invites. We should be careful that this use case still works.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Application-Service Related to AS support A-Sync defects related to /sync T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

No branches or pull requests

1 participant