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

Commit

Permalink
Merge branch 'master' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
richvdh committed Dec 31, 2019
2 parents 7c6b853 + 77661ce commit dc96943
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 16 deletions.
11 changes: 11 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Synapse 1.7.3 (2019-12-31)
==========================

This release fixes a long-standing bug in the state resolution algorithm.

Bugfixes
--------

- Fix exceptions caused by state resolution choking on malformed events. ([\#6608](https://github.com/matrix-org/synapse/issues/6608))


Synapse 1.7.2 (2019-12-20)
==========================

Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
matrix-synapse-py3 (1.7.3) stable; urgency=medium

* New synapse release 1.7.3.

-- Synapse Packaging team <packages@matrix.org> Tue, 31 Dec 2019 10:45:04 +0000

matrix-synapse-py3 (1.7.2) stable; urgency=medium

* New synapse release 1.7.2.
Expand Down
43 changes: 43 additions & 0 deletions docs/sample_log_config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Example log config file for synapse.
#
# This is a YAML file containing a standard Python logging configuration
# dictionary. See [1] for details on the valid settings.
#
# [1]: https://docs.python.org/3.7/library/logging.config.html#configuration-dictionary-schema

version: 1

formatters:
precise:
format: '%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(request)s - %(message)s'

filters:
context:
(): synapse.logging.context.LoggingContextFilter
request: ""

handlers:
file:
class: logging.handlers.RotatingFileHandler
formatter: precise
filename: /home/rav/work/synapse/homeserver.log
maxBytes: 104857600
backupCount: 10
filters: [context]
encoding: utf8
console:
class: logging.StreamHandler
formatter: precise
filters: [context]

loggers:
synapse.storage.SQL:
# beware: increasing this to DEBUG will make synapse log sensitive
# information such as access tokens.
level: INFO

root:
level: INFO
handlers: [file, console]

disable_existing_loggers: false
2 changes: 1 addition & 1 deletion synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
except ImportError:
pass

__version__ = "1.7.2"
__version__ = "1.7.3"

if bool(os.environ.get("SYNAPSE_TEST_PATCH_LOG_CONTEXTS", False)):
# We import here so that we don't have to install a bunch of deps when
Expand Down
52 changes: 37 additions & 15 deletions synapse/state/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,16 +183,20 @@ def _get_power_level_for_sender(room_id, event_id, event_map, state_res_store):

pl = None
for aid in event.auth_event_ids():
aev = yield _get_event(room_id, aid, event_map, state_res_store)
if (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
aev = yield _get_event(
room_id, aid, event_map, state_res_store, allow_none=True
)
if aev and (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
pl = aev
break

if pl is None:
# Couldn't find power level. Check if they're the creator of the room
for aid in event.auth_event_ids():
aev = yield _get_event(room_id, aid, event_map, state_res_store)
if (aev.type, aev.state_key) == (EventTypes.Create, ""):
aev = yield _get_event(
room_id, aid, event_map, state_res_store, allow_none=True
)
if aev and (aev.type, aev.state_key) == (EventTypes.Create, ""):
if aev.content.get("creator") == event.sender:
return 100
break
Expand Down Expand Up @@ -403,10 +407,17 @@ def _iterative_auth_checks(

auth_events = {}
for aid in event.auth_event_ids():
ev = yield _get_event(room_id, aid, event_map, state_res_store)
ev = yield _get_event(
room_id, aid, event_map, state_res_store, allow_none=True
)

if ev.rejected_reason is None:
auth_events[(ev.type, ev.state_key)] = ev
if not ev:
logger.warning(
"auth_event id %s for event %s is missing", aid, event_id
)
else:
if ev.rejected_reason is None:
auth_events[(ev.type, ev.state_key)] = ev

for key in event_auth.auth_types_for_event(event):
if key in resolved_state:
Expand Down Expand Up @@ -457,8 +468,10 @@ def _mainline_sort(
auth_events = pl_ev.auth_event_ids()
pl = None
for aid in auth_events:
ev = yield _get_event(room_id, aid, event_map, state_res_store)
if (ev.type, ev.state_key) == (EventTypes.PowerLevels, ""):
ev = yield _get_event(
room_id, aid, event_map, state_res_store, allow_none=True
)
if ev and (ev.type, ev.state_key) == (EventTypes.PowerLevels, ""):
pl = aid
break

Expand Down Expand Up @@ -506,8 +519,10 @@ def _get_mainline_depth_for_event(event, mainline_map, event_map, state_res_stor
event = None

for aid in auth_events:
aev = yield _get_event(room_id, aid, event_map, state_res_store)
if (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
aev = yield _get_event(
room_id, aid, event_map, state_res_store, allow_none=True
)
if aev and (aev.type, aev.state_key) == (EventTypes.PowerLevels, ""):
event = aev
break

Expand All @@ -516,7 +531,7 @@ def _get_mainline_depth_for_event(event, mainline_map, event_map, state_res_stor


@defer.inlineCallbacks
def _get_event(room_id, event_id, event_map, state_res_store):
def _get_event(room_id, event_id, event_map, state_res_store, allow_none=False):
"""Helper function to look up event in event_map, falling back to looking
it up in the store
Expand All @@ -525,15 +540,22 @@ def _get_event(room_id, event_id, event_map, state_res_store):
event_id (str)
event_map (dict[str,FrozenEvent])
state_res_store (StateResolutionStore)
allow_none (bool): if the event is not found, return None rather than raising
an exception
Returns:
Deferred[FrozenEvent]
Deferred[Optional[FrozenEvent]]
"""
if event_id not in event_map:
events = yield state_res_store.get_events([event_id], allow_rejected=True)
event_map.update(events)
event = event_map[event_id]
assert event is not None
event = event_map.get(event_id)

if event is None:
if allow_none:
return None
raise Exception("Unknown event %s" % (event_id,))

if event.room_id != room_id:
raise Exception(
"In state res for room %s, event %s is in %s"
Expand Down

0 comments on commit dc96943

Please sign in to comment.