diff options
author | Erik Johnston <erikj@element.io> | 2024-05-29 11:14:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-29 11:14:42 +0100 |
commit | bb5a692946e69c7f3686f1cb3fc0833b736f066a (patch) | |
tree | 6fccac75d6c8b4205d5eb1129a2e17003d60aeaf /synapse/media/media_repository.py | |
parent | Merge branch 'master' into develop (diff) | |
download | synapse-bb5a692946e69c7f3686f1cb3fc0833b736f066a.tar.xz |
Fix slipped logging context when media rejected (#17239)
When a module rejects a piece of media we end up trying to close the same logging context twice. Instead of fixing the existing code we refactor to use an async context manager, which is easier to write correctly.
Diffstat (limited to 'synapse/media/media_repository.py')
-rw-r--r-- | synapse/media/media_repository.py | 11 |
1 files changed, 2 insertions, 9 deletions
diff --git a/synapse/media/media_repository.py b/synapse/media/media_repository.py index 0e875132f6..9da8495950 100644 --- a/synapse/media/media_repository.py +++ b/synapse/media/media_repository.py @@ -650,7 +650,7 @@ class MediaRepository: file_info = FileInfo(server_name=server_name, file_id=file_id) - with self.media_storage.store_into_file(file_info) as (f, fname, finish): + async with self.media_storage.store_into_file(file_info) as (f, fname): try: length, headers = await self.client.download_media( server_name, @@ -693,8 +693,6 @@ class MediaRepository: ) raise SynapseError(502, "Failed to fetch remote media") - await finish() - if b"Content-Type" in headers: media_type = headers[b"Content-Type"][0].decode("ascii") else: @@ -1045,14 +1043,9 @@ class MediaRepository: ), ) - with self.media_storage.store_into_file(file_info) as ( - f, - fname, - finish, - ): + async with self.media_storage.store_into_file(file_info) as (f, fname): try: await self.media_storage.write_to_file(t_byte_source, f) - await finish() finally: t_byte_source.close() |