From af4f079bf5ae5bec16868da61c4858b1c68bf672 Mon Sep 17 00:00:00 2001 From: Patrick Cloke Date: Fri, 17 Jul 2020 12:33:19 -0400 Subject: [PATCH] Guard against improper implementations. --- synapse/rest/media/v1/media_storage.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/synapse/rest/media/v1/media_storage.py b/synapse/rest/media/v1/media_storage.py index c943baacfb37..87fe06cf56f6 100644 --- a/synapse/rest/media/v1/media_storage.py +++ b/synapse/rest/media/v1/media_storage.py @@ -14,6 +14,7 @@ # limitations under the License. import contextlib +import inspect import logging import os import shutil @@ -104,7 +105,11 @@ def store_into_file(self, file_info): async def finish(): for provider in self.storage_providers: - await provider.store_file(path, file_info) + # store_file is supposed to return an Awaitable or Deferred, but + # guard against improper implementations. + result = provider.store_file(path, file_info) + if inspect.isawaitable(result) or isinstance(result, defer.Deferred): + await result finished_called[0] = True