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

Convert more of the media code to async/await #7873

Merged
merged 8 commits into from
Jul 24, 2020
Merged

Conversation

clokep
Copy link
Member

@clokep clokep commented Jul 16, 2020

So this converts most of the remaining media code to async/await. The remaining pieces after this are the StorageProvider and sub-classes, but I think those need changes to the S3 code at the same time? I'm not really sure about that.

I've held off on pushing these changes for a while since the code surrounding them is confusing and I was not super confident. Please review thoroughly (and also consider if any of this will affect the S3 provider or other third-party providers).

@clokep clokep requested a review from a team July 16, 2020 16:46
@richvdh richvdh self-assigned this Jul 17, 2020
synapse/rest/media/v1/media_storage.py Outdated Show resolved Hide resolved
for provider in self.storage_providers:
yield provider.store_file(path, file_info)
await provider.store_file(path, file_info)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sadly I don't think we can rely on the storage providers honouring their interface. In particular, see https://github.com/matrix-org/synapse-s3-storage-provider/blob/master/s3_storage_provider.py#L96-L98: reactor.callInThread returns None, and make_deferred_yieldable passes it through.

in other words: better add some safety checks here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some checks in af4f079 for this, hopefully they make sense!

@richvdh
Copy link
Member

richvdh commented Jul 17, 2020

The remaining pieces after this are the StorageProvider and sub-classes, but I think those need changes to the S3 code at the same time?

that shouldn't be needed. Basically if we make sure that wherever we get a result from StorageProvider.{fetch,store_file} we handle either Deferreds or Coroutines, then we can change the StorageProvider interface to say that the methods return Awaitables instead, and the S3 storage provider will still be compatible. Then we can update the StorageProvider implementations to be async.

@richvdh richvdh assigned clokep and unassigned richvdh Jul 17, 2020
@clokep
Copy link
Member Author

clokep commented Jul 17, 2020

Thanks! :) I'll take another look and see how I can add that isolation in.

@richvdh
Copy link
Member

richvdh commented Jul 17, 2020

I think you could merge this as-is (well, after fixing the issues) and do the rest of StorageProvider as another step.

@clokep
Copy link
Member Author

clokep commented Jul 17, 2020

I think you could merge this as-is (well, after fixing the issues) and do the rest of StorageProvider as another step.

I converted the other couple of methods here (the ones that use StorageProvider.fetch as well in this PR. I'll tackle the StorageProvider class itself in a separate PR, I think. I added the same guards as for store_file, although the S3 storage provider seems to be properly implemented in this case.

@clokep clokep requested a review from richvdh July 17, 2020 17:51
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@clokep clokep merged commit 5ea29d7 into develop Jul 24, 2020
@clokep clokep deleted the clokep/async-media branch July 24, 2020 13:39
anoadragon453 added a commit that referenced this pull request Jul 28, 2020
…rove_test_times

* 'develop' of github.com:matrix-org/synapse: (148 commits)
  Add script for finding files with unix line terminators (#7965)
  Convert the remaining media repo code to async / await. (#7947)
  Convert a synapse.events to async/await. (#7949)
  Convert groups and visibility code to async / await. (#7951)
  Convert push to async/await. (#7948)
  update changelog
  1.18.0rc1
  Fix error reporting when using `opentracing.trace` (#7961)
  Fix typing replication not being handled on master (#7959)
  Remove hacky error handling for inlineDeferreds. (#7950)
  Convert tests/rest/admin/test_room.py to unix file endings (#7953)
  Support oEmbed for media previews. (#7920)
  Convert state resolution to async/await (#7942)
  Fix up types and comments that refer to Deferreds. (#7945)
  Do not convert async functions to Deferreds in the interactive_auth_handler (#7944)
  Convert more of the media code to async/await (#7873)
  Return an empty body for OPTIONS requests. (#7886)
  Downgrade warning on client disconnect to INFO (#7928)
  Convert presence handler helpers to async/await. (#7939)
  Update the auth providers to be async. (#7935)
  ...
babolivier pushed a commit that referenced this pull request Sep 1, 2021
* commit 'f88c48f3b':
  1.18.0rc1
  Fix error reporting when using `opentracing.trace` (#7961)
  Fix typing replication not being handled on master (#7959)
  Remove hacky error handling for inlineDeferreds. (#7950)
  Convert tests/rest/admin/test_room.py to unix file endings (#7953)
  Support oEmbed for media previews. (#7920)
  Convert state resolution to async/await (#7942)
  Fix up types and comments that refer to Deferreds. (#7945)
  Do not convert async functions to Deferreds in the interactive_auth_handler (#7944)
  Convert more of the media code to async/await (#7873)
  Return an empty body for OPTIONS requests. (#7886)
  Downgrade warning on client disconnect to INFO (#7928)
  Convert presence handler helpers to async/await. (#7939)
  Update the auth providers to be async. (#7935)
  Put a cache on `/state_ids` (#7931)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants