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

Clean up some logging #6515

Merged
merged 1 commit into from
Dec 11, 2019
Merged

Clean up some logging #6515

merged 1 commit into from
Dec 11, 2019

Conversation

richvdh
Copy link
Member

@richvdh richvdh commented Dec 10, 2019

This just makes some of the logging easier to follow when things start
going wrong.

This just makes some of the logging easier to follow when things start going
wrong.
@@ -182,7 +182,7 @@ def on_receive_pdu(self, origin, pdu, sent_to_us_directly=False):
room_id = pdu.room_id
event_id = pdu.event_id

logger.info("[%s %s] handling received PDU: %s", room_id, event_id, pdu)
Copy link
Member

Choose a reason for hiding this comment

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

Why remove the prefixing? I find it quite useful to track how we're processing an event?

Copy link
Member Author

Choose a reason for hiding this comment

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

because it's in the logcontext anyway.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, so it is. I had forgotten the log context isn't the generic request one. Carry on.

raise Exception(
"Error fetching missing prev_events for %s: %s"
% (event_id, e)
)
Copy link
Member

Choose a reason for hiding this comment

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

I'd be tempted to not include e and rely on the exception chaining (raise Exception(..) from e).

(I assume we've checked that get_missing_events_for_pdu doesn't raise any expected exceptions.)

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd be tempted to not include e and rely on the exception chaining (raise Exception(..) from e).

I tried that. It made for remarkably unreadable errors, not least because the exception chain is epic.

Exception chaining happens by default when you raise an exception from an except block, afaik

Copy link
Member Author

Choose a reason for hiding this comment

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

(I assume we've checked that get_missing_events_for_pdu doesn't raise any expected exceptions.)

well: first, I've looked at the places on_receive_pdu is called (ie, the places that might care that we turn one sort of exception into a generic Exception). There are two such places: _handle_queued_pdus, in which all exceptions are treated equally, and get_missing_events_for_pdu (again), which does treat FederationError with code=403 specially.

Then going down through get_missing_events_for_pdu, the only things which might raise a FederationError are federation_client.get_missing_events (which I'm 99% sure doesn't), and on_receive_pdu which, as discussed, filters out such exceptions. So I'm reasonably confident it's not possible for get_missing_events_for_pdu to raise a FederationError with code=403, and therefore this change shouldn't make any difference.

Copy link
Member

@erikjohnston erikjohnston left a comment

Choose a reason for hiding this comment

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

Up to you about using raise .. from ..

@richvdh richvdh merged commit 7c429f9 into develop Dec 11, 2019
@richvdh richvdh deleted the rav/event_auth/12 branch December 11, 2019 14:32
@richvdh
Copy link
Member Author

richvdh commented Dec 11, 2019

oh, another thing that's worth noting about relying on the exception chaining:

the exception message here actually ends up getting sent back to the sending server. So for example:

{
  "pdus": {
    "$gTbOW9yxHJ9SkILmPz42b5t_NpN2XnD5Dk_SO_7cCBM": {
      "error": "Error fetching missing prev_events for $gTbOW9yxHJ9SkILmPz42b5t_NpN2XnD5Dk_SO_7cCBM: 404: Could not find event $-xeoZouRJKbRQ_MoNe5hff5gzaumxzIwcfscKgAtQy8"
    }
  }
}

There are other bugs that mean that error is completely bogus ($-xeo actually failed auth, rather than being missing), but it's progress in the right direction imho

babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit '7c429f92d':
  Clean up some logging (#6515)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants