From 52b2336e1875cf8ce4b7f6868f9a4ccc99f5b71b Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 22 May 2023 10:14:57 -0500 Subject: [PATCH 1/4] Fix @trace not wrapping some state methods correctly ``` master | 2023-05-21 09:30:09,288 - synapse.logging.opentracing - 940 - ERROR - POST-1 - @trace may not have wrapped StateStorageController.get_state_for_groups correctly! The function is not async but returned a coroutine ``` --- synapse/storage/controllers/state.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/synapse/storage/controllers/state.py b/synapse/storage/controllers/state.py index 06a80869eb4a..f674ef93fd31 100644 --- a/synapse/storage/controllers/state.py +++ b/synapse/storage/controllers/state.py @@ -175,9 +175,9 @@ async def get_state_groups( @trace @tag_args - def _get_state_groups_from_groups( + async def _get_state_groups_from_groups( self, groups: List[int], state_filter: StateFilter - ) -> Awaitable[Dict[int, StateMap[str]]]: + ) -> Dict[int, StateMap[str]]: """Returns the state groups for a given set of groups, filtering on types of state events. @@ -190,7 +190,9 @@ def _get_state_groups_from_groups( Dict of state group to state map. """ - return self.stores.state._get_state_groups_from_groups(groups, state_filter) + return await self.stores.state._get_state_groups_from_groups( + groups, state_filter + ) @trace @tag_args @@ -349,9 +351,9 @@ async def get_state_ids_for_event( @trace @tag_args - def get_state_for_groups( + async def get_state_for_groups( self, groups: Iterable[int], state_filter: Optional[StateFilter] = None - ) -> Awaitable[Dict[int, MutableStateMap[str]]]: + ) -> Dict[int, MutableStateMap[str]]: """Gets the state at each of a list of state groups, optionally filtering by type/state_key @@ -363,7 +365,7 @@ def get_state_for_groups( Returns: Dict of state group to state map. """ - return self.stores.state._get_state_for_groups( + return await self.stores.state._get_state_for_groups( groups, state_filter or StateFilter.all() ) From de57cc66b9ea5ad22a803161c17765f93d1abfcb Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 22 May 2023 14:14:30 -0500 Subject: [PATCH 2/4] Add changelog: --- changelog.d/15647.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/15647.bugfix diff --git a/changelog.d/15647.bugfix b/changelog.d/15647.bugfix new file mode 100644 index 000000000000..b92a9e0a9b94 --- /dev/null +++ b/changelog.d/15647.bugfix @@ -0,0 +1 @@ +Fix `@trace` not wrapping some state related operations that return coroutines correctly. From 2f9dc45f87b1fdcf59c466ca81170be7c852115e Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 22 May 2023 18:08:15 -0500 Subject: [PATCH 3/4] Remove unused import --- synapse/storage/controllers/state.py | 1 - 1 file changed, 1 deletion(-) diff --git a/synapse/storage/controllers/state.py b/synapse/storage/controllers/state.py index f674ef93fd31..7089b0a1d85d 100644 --- a/synapse/storage/controllers/state.py +++ b/synapse/storage/controllers/state.py @@ -16,7 +16,6 @@ TYPE_CHECKING, AbstractSet, Any, - Awaitable, Callable, Collection, Dict, From 305cb62593c72a09909e5d762d1a8f49b3bad2c2 Mon Sep 17 00:00:00 2001 From: Eric Eastwood Date: Mon, 22 May 2023 18:15:39 -0500 Subject: [PATCH 4/4] Use same changelog as #15610 so they merge --- changelog.d/15647.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.d/15647.bugfix b/changelog.d/15647.bugfix index b92a9e0a9b94..2eff30f6e3f3 100644 --- a/changelog.d/15647.bugfix +++ b/changelog.d/15647.bugfix @@ -1 +1 @@ -Fix `@trace` not wrapping some state related operations that return coroutines correctly. +Instrument `state` and `state_group` storage-related operations to better picture what's happening when tracing.