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

Commit 2c63cdc

Browse files
Add debug logs to figure out why an event was filtered (#14095)
Spawned while investigating #13944 This way we might get some more context whenever an `403 Forbidden - body: {"errcode":"M_FORBIDDEN","error":"You don't have permission to access that event."}` error is produced. `log_config.yaml` ```yaml loggers: synapse: level: INFO synapse.visibility: level: DEBUG ```
1 parent 6fee2f4 commit 2c63cdc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

changelog.d/14095.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add debug logs to figure out why an event was filtered out of the client response.

synapse/visibility.py

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,15 @@ async def filter_events_for_client(
8484
"""
8585
# Filter out events that have been soft failed so that we don't relay them
8686
# to clients.
87+
events_before_filtering = events
8788
events = [e for e in events if not e.internal_metadata.is_soft_failed()]
89+
if len(events_before_filtering) != len(events):
90+
if logger.isEnabledFor(logging.DEBUG):
91+
logger.debug(
92+
"filter_events_for_client: Filtered out soft-failed events: Before=%s, After=%s",
93+
[event.event_id for event in events_before_filtering],
94+
[event.event_id for event in events],
95+
)
8896

8997
types = (_HISTORY_VIS_KEY, (EventTypes.Member, user_id))
9098

@@ -301,6 +309,10 @@ def _check_client_allowed_to_see_event(
301309
_check_filter_send_to_client(event, clock, retention_policy, sender_ignored)
302310
== _CheckFilter.DENIED
303311
):
312+
logger.debug(
313+
"_check_client_allowed_to_see_event(event=%s): Filtered out event because `_check_filter_send_to_client` returned `_CheckFilter.DENIED`",
314+
event.event_id,
315+
)
304316
return None
305317

306318
if event.event_id in always_include_ids:
@@ -312,9 +324,17 @@ def _check_client_allowed_to_see_event(
312324
# for out-of-band membership events (eg, incoming invites, or rejections of
313325
# said invite) for the user themselves.
314326
if event.type == EventTypes.Member and event.state_key == user_id:
315-
logger.debug("Returning out-of-band-membership event %s", event)
327+
logger.debug(
328+
"_check_client_allowed_to_see_event(event=%s): Returning out-of-band-membership event %s",
329+
event.event_id,
330+
event,
331+
)
316332
return event
317333

334+
logger.debug(
335+
"_check_client_allowed_to_see_event(event=%s): Filtered out event because it's an outlier",
336+
event.event_id,
337+
)
318338
return None
319339

320340
if state is None:
@@ -337,11 +357,21 @@ def _check_client_allowed_to_see_event(
337357

338358
membership_result = _check_membership(user_id, event, visibility, state, is_peeking)
339359
if not membership_result.allowed:
360+
logger.debug(
361+
"_check_client_allowed_to_see_event(event=%s): Filtered out event because the user can't see the event because of their membership, membership_result.allowed=%s membership_result.joined=%s",
362+
event.event_id,
363+
membership_result.allowed,
364+
membership_result.joined,
365+
)
340366
return None
341367

342368
# If the sender has been erased and the user was not joined at the time, we
343369
# must only return the redacted form.
344370
if sender_erased and not membership_result.joined:
371+
logger.debug(
372+
"_check_client_allowed_to_see_event(event=%s): Returning pruned event because `sender_erased` and the user was not joined at the time",
373+
event.event_id,
374+
)
345375
event = prune_event(event)
346376

347377
return event

0 commit comments

Comments
 (0)