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

Commit

Permalink
Fix @trace not wrapping some state methods that return coroutines c…
Browse files Browse the repository at this point in the history
…orrectly (#15647)

```
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
```

Tracing instrumentation for these functions originally introduced in #15610
  • Loading branch information
MadLittleMods authored May 23, 2023
1 parent 7c9b917 commit 379eb2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/15647.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Instrument `state` and `state_group` storage-related operations to better picture what's happening when tracing.
15 changes: 8 additions & 7 deletions synapse/storage/controllers/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
TYPE_CHECKING,
AbstractSet,
Any,
Awaitable,
Callable,
Collection,
Dict,
Expand Down Expand Up @@ -175,9 +174,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.
Expand All @@ -190,7 +189,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
Expand Down Expand Up @@ -349,9 +350,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
Expand All @@ -363,7 +364,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()
)

Expand Down

0 comments on commit 379eb2d

Please sign in to comment.