Skip to content
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

Be more tolerant towards weird data in transaction pdus #17893

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

morguldir
Copy link

@morguldir morguldir commented Oct 31, 2024

Pull Request Checklist

Complement test: matrix-org/complement#743

@morguldir morguldir requested a review from a team as a code owner October 31, 2024 18:44
@@ -469,14 +475,27 @@ async def _handle_pdus_in_txn(
logger.info("Ignoring PDU: %s", e)
continue

event = event_from_pdu_json(p, room_version)
if possible_event_id != "<Unknown>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is trying to match up to the magic value we set at

# We try and pull out an event ID so that if later checks fail we
# can log something sensible. We don't mandate an event ID here in
# case future event formats get rid of the key.
possible_event_id = p.get("event_id", "<Unknown>")

We should make this a constant

@@ -0,0 +1 @@
Fix a bug where all messages from a server could be blocked because of one bad event. Contributed by @morguldir
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there more context for the issue you ran into specifically? Some issue that should be linked?

@@ -469,14 +475,27 @@ async def _handle_pdus_in_txn(
logger.info("Ignoring PDU: %s", e)
continue

event = event_from_pdu_json(p, room_version)
if possible_event_id != "<Unknown>":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(needs wrapping)

Suggested change
if possible_event_id != "<Unknown>":
# An event should only have an event_id at this point if it's for a v1/v2 room.
# In future room versions, the `event_id` is derived from the event canonical JSON.
#
# So if we see a `event_id` but the room version doesn't support v1/v2 events, it's invalid and we should reject it.
if possible_event_id != "<Unknown>":

logger.info(f"Rejecting event {possible_event_id} from {origin} "
f"because the event was made for a v1 room, "
f"while {room_id} is a v{room_version.identifier} room")
pdu_results[possible_event_id] = {"error": "Event ID incorrectly supplied in non-v1/v2 room"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
pdu_results[possible_event_id] = {"error": "Event ID incorrectly supplied in non-v1/v2 room"}
pdu_results[possible_event_id] = {"error": "Event ID should not be supplied in non-v1/v2 room"}

Comment on lines +489 to +490
if possible_event_id != "<Unknown>":
pdu_results[possible_event_id] = {"error": f"Failed to convert json into event, {e}"}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(needs wrapping)

Suggested change
if possible_event_id != "<Unknown>":
pdu_results[possible_event_id] = {"error": f"Failed to convert json into event, {e}"}
# We can only provide feedback to the federating server if we can determine what the event_id is but since we we failed to parse the event, we can't derive the `event_id` so there is nothing to use as the `pdu_results` key. Best we can do is just log for our own record and move on.
if possible_event_id != "<Unknown>":
pdu_results[possible_event_id] = {"error": f"Failed to convert json into event, {e}"}

@@ -56,7 +56,11 @@
SynapseError,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@morguldir Are you up for adding a test for this? Probably something in tests/federation/test_federation_server.py, make a request like this and then assert that the other PDU's in the transaction besides the corrupted one were persisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants