-
Notifications
You must be signed in to change notification settings - Fork 186
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
base: develop
Are you sure you want to change the base?
Be more tolerant towards weird data in transaction pdus #17893
Conversation
@@ -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>": |
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.
It looks like this is trying to match up to the magic value we set at
synapse/synapse/federation/federation_server.py
Lines 446 to 449 in eac170b
# 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 |
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.
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>": |
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.
(needs wrapping)
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"} |
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.
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"} |
if possible_event_id != "<Unknown>": | ||
pdu_results[possible_event_id] = {"error": f"Failed to convert json into event, {e}"} |
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.
(needs wrapping)
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, |
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.
@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.
Pull Request Checklist
Complement test: matrix-org/complement#743