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

Fix exception when using MSC3030 to look for remote federated events before room creation #13197

Conversation

MadLittleMods
Copy link
Contributor

@MadLittleMods MadLittleMods commented Jul 6, 2022

Fix exception when using MSC3030 to look for remote federated events before room creation.

Complement tests: matrix-org/complement#405

This happens when you have some messages imported before the room is created.
Then use MSC3030 to look backwards before the room creation from a remote
federated server. The server won't find anything locally, but will ask over
federation which will have the remote event. The previous logic would
choke on not having the local event assigned.

Failed to fetch /timestamp_to_event from hs2 because of exception(UnboundLocalError) local variable 'local_event' referenced before assignment args=("local variable 'local_event' referenced before assignment",)

Dev notes

synapse_main | 2022-07-06 13:32:48,807 - synapse.handlers.room - 1369 - INFO - GET-6 - get_event_for_timestamp: locally, we found event_id=None closest to timestamp=1657114367164
synapse_main | 2022-07-06 13:32:48,808 - synapse.handlers.room - 1404 - INFO - GET-6 - get_event_for_timestamp: locally, we found event_id=None closest to timestamp=1657114367164 which is next to a gap in event history so we're asking other homeservers first

synapse_main | 2022-07-06 13:32:48,900 - synapse.handlers.room - 1425 - INFO - GET-6 - get_event_for_timestamp: response from domain(hs1)=TimestampToEventResponse(event_id='$6N0qwxOfLXTf7BZRzc5J9LXEPz1dXbWhD1IeAhecNRM', origin_server_ts=1641189600000, data={'event_id': '$6N0qwxOfLXTf7BZRzc5J9LXEPz1dXbWhD1IeAhecNRM', 'origin_server_ts': 1641189600000})
synapse_main | 2022-07-06 13:32:48,903 - synapse.handlers.room - 1464 - WARNING - GET-6 - Failed to fetch /timestamp_to_event from hs1 because of exception(UnboundLocalError) local variable 'local_event' referenced before assignment args=("local variable 'local_event' referenced before assignment",)

The got is because it has those state events locally even though that user joined after those events. We want the imported event which has a timestamp before the creation event.

                   -- oldest events --
                   $azd78vChQWi-mL8ujkvYDaGUoBgf5LeiJtcd96SjuVw (1657114367199) - m.room.create
                   $nrXeQWObbNdV1bdT_aV5imUHm-Y7RJjv4t2Bf2Q5t04 (1657114367381) - m.room.member
                   $_8LZSYqibJvowol8p9bkd-tFzUEKrUZ40I6ZdBXLu88 (1657114367431) - m.room.power_levels
                   $ZPCpSJy-24c_WIHTr3RFmVETRE5yzHl9xT27ek5DkZ4 (1657114367479) - m.room.join_rules
             (got) $_zb4erdxtTYrqOvRdqxTKONKzEk8iq9iPDfjx9Ey6VY (1657114367522) - m.room.history_visibility
                   $l8DQs4X8PiZqqsHCDHMnkjmPMJruwtE3biWXW7TJPCc (1657114367572) - m.room.message
                   $gQTxarzOc3rzF1FLr3pcCNyxJtMdwbfnSZraLLXGa8U (1657114367649) - m.room.message
                   $kRFvZBZT9p4nLqSGRfFmTUER-GKosW6aYpL_DdSKbBM (1657114367702) - m.room.member
  (want, imported) $6N0qwxOfLXTf7BZRzc5J9LXEPz1dXbWhD1IeAhecNRM (1641189600000) - m.room.message
                   $8h4X8YiVmOqTj_HSRUCY4LuiO8oA3xOVR0WjGMLPgJU (1657114368559) - m.room.member
                   -- newest events --

Pull Request Checklist

  • Pull request is based on the develop branch
  • Pull request includes a changelog file. The entry should:
    • Be a short description of your change which makes sense to users. "Fixed a bug that prevented receiving messages from other servers." instead of "Moved X method from EventStore to EventWorkerStore.".
    • Use markdown where necessary, mostly for code blocks.
    • End with either a period (.) or an exclamation mark (!).
    • Start with a capital letter.
    • Feel free to credit yourself, by adding a sentence "Contributed by @github_username." or "Contributed by [Your Name]." to the end of the entry.
  • Pull request includes a sign off
  • Code style is correct
    (run the linters)

…before room creation

This happens when you have some messages imported before the room is created.
Then use MSC3030 to look backwards before the room creation from a remote
federated server. The server won't find anything locally, but will ask over
federation which will have the remote event. The previous logic would
choke on not having the local event assigned.

```
Failed to fetch /timestamp_to_event from hs2 because of exception(UnboundLocalError) local variable 'local_event' referenced before assignment args=("local variable 'local_event' referenced before assignment",)
```
@MadLittleMods MadLittleMods added the T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues. label Jul 6, 2022
MadLittleMods added a commit to matrix-org/complement that referenced this pull request Jul 6, 2022
@MadLittleMods MadLittleMods marked this pull request as ready for review July 6, 2022 16:44
@MadLittleMods MadLittleMods requested a review from a team as a code owner July 6, 2022 16:44
@MadLittleMods MadLittleMods requested a review from squahtx July 7, 2022 13:37
@MadLittleMods MadLittleMods merged commit a962c5a into develop Jul 7, 2022
@MadLittleMods MadLittleMods deleted the madlittlemods/fix-msc3030-unbound-local-variable-when-looking-before-room-creation branch July 7, 2022 16:52
@@ -1375,6 +1375,7 @@ async def get_event_for_timestamp(
# the timestamp given and the event we were able to find locally
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the review @squahtx 🐰

MadLittleMods added a commit to matrix-org/complement that referenced this pull request Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
T-Defect Bugs, crashes, hangs, security vulnerabilities, or other reported issues.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants