From 82db25a7bb338818695faa055fbb12222808a332 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 29 Jul 2020 14:52:42 -0400 Subject: [PATCH 1/2] Guard against different return values for remove_pusher. --- changelog.d/7981.misc | 1 + synapse/push/httppusher.py | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelog.d/7981.misc diff --git a/changelog.d/7981.misc b/changelog.d/7981.misc new file mode 100644 index 000000000000..dfe4c03171d6 --- /dev/null +++ b/changelog.d/7981.misc @@ -0,0 +1 @@ +Convert various parts of the codebase to async/await. diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index 4c469efb20e2..a5b64292a4ca 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -13,6 +13,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import inspect import logging from prometheus_client import Counter @@ -296,7 +297,11 @@ async def _process_one(self, push_action): ) else: logger.info("Pushkey %s was rejected: removing", pk) - await self.hs.remove_pusher(self.app_id, pk, self.user_id) + # remove_pusher might return an awaitable (for the main + # process) or None (for a worker process). + result = self.hs.remove_pusher(self.app_id, pk, self.user_id) + if inspect.isawaitable(result): + await result return True async def _build_notification_dict(self, event, tweaks, badge): From 7bd43a9a9b63bc245d838211a1bb20ba05b2ee73 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Wed, 29 Jul 2020 15:53:45 -0400 Subject: [PATCH 2/2] Use async function instead. --- synapse/app/generic_worker.py | 2 +- synapse/push/httppusher.py | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/synapse/app/generic_worker.py b/synapse/app/generic_worker.py index ec0dbddb8ce3..6e8130351c69 100644 --- a/synapse/app/generic_worker.py +++ b/synapse/app/generic_worker.py @@ -628,7 +628,7 @@ def start_listening(self, listeners: Iterable[ListenerConfig]): self.get_tcp_replication().start_replication(self) - def remove_pusher(self, app_id, push_key, user_id): + async def remove_pusher(self, app_id, push_key, user_id): self.get_tcp_replication().send_remove_pusher(app_id, push_key, user_id) def build_replication_data_handler(self): diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index a5b64292a4ca..4c469efb20e2 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -13,7 +13,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import inspect import logging from prometheus_client import Counter @@ -297,11 +296,7 @@ async def _process_one(self, push_action): ) else: logger.info("Pushkey %s was rejected: removing", pk) - # remove_pusher might return an awaitable (for the main - # process) or None (for a worker process). - result = self.hs.remove_pusher(self.app_id, pk, self.user_id) - if inspect.isawaitable(result): - await result + await self.hs.remove_pusher(self.app_id, pk, self.user_id) return True async def _build_notification_dict(self, event, tweaks, badge):