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

A pair of tiny cleanups in the federation request code. #8401

Merged
merged 1 commit into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/8401.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A pair of tiny cleanups in the federation request code.
2 changes: 1 addition & 1 deletion synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ async def on_receive_pdu(self, origin, pdu, sent_to_us_directly=False) -> None:
raise Exception(
"Error fetching missing prev_events for %s: %s"
% (event_id, e)
)
) from e
Copy link
Member Author

Choose a reason for hiding this comment

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

the idea here is to change this:

2020-09-21 06:01:39,826 - synapse.federation.federation_server - 309 - ERROR - PUT-1098178-$s5rml0MNFzN0HCySGnCzRn1CXnGiIvoQCfYtL68-ucI- Failed to handle PDU $s5rml0MNFzN0HCySGnCzRn1CXnGiIvoQCfYtL68-ucI
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 276, in on_receive_pdu
    origin, pdu, prevs, min_depth
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 540, in _get_missing_events_for_pdu
    await self.on_receive_pdu(origin, ev, sent_to_us_directly=False)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 418, in on_receive_pdu
    await self._process_received_pdu(origin, pdu, state=state)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 701, in _process_received_pdu
    context = await self._handle_new_event(origin, event, state=state)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1901, in _handle_new_event
    [(event, context)], backfilled=backfilled
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2918, in persist_events_and_notify
    backfilled=backfilled,
  File "/usr/local/lib/python3.7/site-packages/synapse/replication/http/_base.py", line 196, in send_request
    result = await request_func(uri, data, headers=headers)
  File "/usr/local/lib/python3.7/site-packages/synapse/http/client.py", line 430, in post_json_get_json
    "POST", uri, headers=Headers(actual_headers), data=json_str
  File "/usr/local/lib/python3.7/site-packages/synapse/http/client.py", line 332, in request
    response = await make_deferred_yieldable(request_deferred)
twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure twisted.internet.defer.CancelledError: >]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/federation/federation_server.py", line 298, in process_pdus_for_room
    await self._handle_received_pdu(origin, pdu)
  File "/usr/local/lib/python3.7/site-packages/synapse/federation/federation_server.py", line 683, in _handle_received_pdu
    await self.handler.on_receive_pdu(origin, pdu, sent_to_us_directly=True)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 281, in on_receive_pdu
    % (event_id, e)
Exception: Error fetching missing prev_events for $s5rml0MNFzN0HCySGnCzRn1CXnGiIvoQCfYtL68-ucI: [<twisted.python.failure.Failure twisted.internet.defer.CancelledError: >]

Into this:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 276, in on_receive_pdu
    origin, pdu, prevs, min_depth
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 540, in _get_missing_events_for_pdu
    await self.on_receive_pdu(origin, ev, sent_to_us_directly=False)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 418, in on_receive_pdu
    await self._process_received_pdu(origin, pdu, state=state)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 701, in _process_received_pdu
    context = await self._handle_new_event(origin, event, state=state)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 1901, in _handle_new_event
    [(event, context)], backfilled=backfilled
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 2918, in persist_events_and_notify
    backfilled=backfilled,
  File "/usr/local/lib/python3.7/site-packages/synapse/replication/http/_base.py", line 196, in send_request
    result = await request_func(uri, data, headers=headers)
  File "/usr/local/lib/python3.7/site-packages/synapse/http/client.py", line 430, in post_json_get_json
    "POST", uri, headers=Headers(actual_headers), data=json_str
  File "/usr/local/lib/python3.7/site-packages/synapse/http/client.py", line 332, in request
    response = await make_deferred_yieldable(request_deferred)
twisted.web._newclient.ResponseNeverReceived: [<twisted.python.failure.Failure twisted.internet.defer.CancelledError: >]

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/synapse/federation/federation_server.py", line 298, in process_pdus_for_room
    await self._handle_received_pdu(origin, pdu)
  File "/usr/local/lib/python3.7/site-packages/synapse/federation/federation_server.py", line 683, in _handle_received_pdu
    await self.handler.on_receive_pdu(origin, pdu, sent_to_us_directly=True)
  File "/usr/local/lib/python3.7/site-packages/synapse/handlers/federation.py", line 281, in on_receive_pdu
    % (event_id, e)
Exception: Error fetching missing prev_events for $s5rml0MNFzN0HCySGnCzRn1CXnGiIvoQCfYtL68-ucI: [<twisted.python.failure.Failure twisted.internet.defer.CancelledError: >]

it's maybe marginally clearer?


# Update the set of things we've seen after trying to
# fetch the missing stuff
Expand Down
2 changes: 0 additions & 2 deletions synapse/http/matrixfederationclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,6 @@ async def _send_request(
)

response = await request_deferred
except TimeoutError as e:
raise RequestSendFailed(e, can_retry=True) from e
Comment on lines -476 to -477
Copy link
Member Author

Choose a reason for hiding this comment

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

this was never actually being hit, because it was catching the wrong type of TimeoutError, but in any case it's redundant since the except Exception clause below is the same.

(I'm not really sure why the additional clause was added. I think it was to avoid some logging, which was later removed in a0f574f#diff-eaf1ef90b23076afc24efff2afdfe772L439.)

except DNSLookupError as e:
raise RequestSendFailed(e, can_retry=retry_on_dns_fail) from e
except Exception as e:
Expand Down