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

Asynchronous Uploads #15503

Merged
merged 29 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3651bf5
Remove re-assignment of self.clock in UploadResource
sumnerevans Mar 25, 2022
1bcb587
config: add option to rate limit media creation
sumnerevans Apr 15, 2022
f9e0504
config: add option for how long to wait until media ID expires
sumnerevans May 31, 2022
f0d53e8
media/create: add /create endpoint
sumnerevans Apr 20, 2023
d29b9d3
changelog: add entry for async uploads
sumnerevans Apr 16, 2022
e2007fa
media/upload: add support for async uploads
sumnerevans Apr 20, 2023
baa96f6
media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Apr 28, 2023
e4c4f36
tests/media/test_media_storage: add timeout_ms
sumnerevans Jun 9, 2023
a6b2192
config: add option for max pending media uploads
sumnerevans Jun 9, 2023
e2e4ad5
media/create: enforce limit on number of pending uploads
sumnerevans Jun 9, 2023
97c792c
media/create: don't store unused expiration time in database
sumnerevans Sep 5, 2023
52e8915
media/upload: split async servlet into separate class
clokep Oct 26, 2023
961bfa0
Do not fail upload if thumbnailing fails.
clokep Nov 8, 2023
b49a50b
fixup! media/upload: add support for async uploads
sumnerevans Nov 9, 2023
4e4e8d0
fixup! media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Nov 9, 2023
37c7970
fixup! media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Nov 9, 2023
acadec0
fixup! media/create: add /create endpoint
sumnerevans Nov 9, 2023
58364ad
fixup! media/create: don't store unused expiration time in database
sumnerevans Nov 9, 2023
a514c84
fixup! media/create: enforce limit on number of pending uploads
sumnerevans Nov 9, 2023
b298258
fixup! media/create: enforce limit on number of pending uploads
sumnerevans Nov 9, 2023
1cff556
fixup! media/create: add /create endpoint
sumnerevans Nov 13, 2023
07afcfb
fixup! media/create: enforce limit on number of pending uploads
sumnerevans Nov 13, 2023
c377b5d
fixup! media/upload: split async servlet into separate class
sumnerevans Nov 13, 2023
6974380
fixup! media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Nov 14, 2023
8b225ee
fixup! media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Nov 14, 2023
c5e4f04
fixup! media/{download,thumbnail}: support timeout_ms parameter
sumnerevans Nov 14, 2023
c3d3afe
fixup! media/create: enforce limit on number of pending uploads
sumnerevans Nov 14, 2023
8debbdf
Fix reference to potentially undefined config.
clokep Nov 15, 2023
38badff
Appease mypy
clokep Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/15503.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for asynchronous uploads as defined by [MSC2246](https://github.com/matrix-org/matrix-spec-proposals/pull/2246). Contributed by @sumnerevans at @beeper.
34 changes: 34 additions & 0 deletions docs/usage/configuration/config_documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,19 @@ rc_third_party_invite:
burst_count: 10
```
---
### `rc_media_create`

This option ratelimits creation of MXC URIs via the `/_matrix/media/v1/create`
endpoint based on the account that's creating the media. Defaults to
`per_second: 10`, `burst_count: 50`.

Example configuration:
```yaml
rc_media_create:
per_second: 10
burst_count: 50
```
---
### `rc_federation`

Defines limits on federation requests.
Expand Down Expand Up @@ -1814,6 +1827,27 @@ Example configuration:
media_store_path: "DATADIR/media_store"
```
---
### `max_pending_media_uploads`

How many *pending media uploads* can a given user have? A pending media upload
is a created MXC URI that (a) is not expired (the `unused_expires_at` timestamp
has not passed) and (b) the media has not yet been uploaded for. Defaults to 5.

Example configuration:
```yaml
max_pending_media_uploads: 5
```
clokep marked this conversation as resolved.
Show resolved Hide resolved
---
### `unused_expiration_time`

How long to wait in milliseconds before expiring created media IDs. Defaults to
"24h"

Example configuration:
```yaml
unused_expiration_time: "1h"
```
---
### `media_storage_providers`

Media storage providers allow media to be stored in different
Expand Down
2 changes: 2 additions & 0 deletions synapse/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class Codes(str, Enum):
USER_DEACTIVATED = "M_USER_DEACTIVATED"
# USER_LOCKED = "M_USER_LOCKED"
USER_LOCKED = "ORG_MATRIX_MSC3939_USER_LOCKED"
NOT_YET_UPLOADED = "M_NOT_YET_UPLOADED"
CANNOT_OVERWRITE_MEDIA = "M_CANNOT_OVERWRITE_MEDIA"

# Part of MSC3848
# https://github.com/matrix-org/matrix-spec-proposals/pull/3848
Expand Down
7 changes: 7 additions & 0 deletions synapse/config/ratelimiting.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,3 +204,10 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"rc_third_party_invite",
defaults={"per_second": 0.0025, "burst_count": 5},
)

# Ratelimit create media requests:
self.rc_media_create = RatelimitSettings.parse(
config,
"rc_media_create",
defaults={"per_second": 10, "burst_count": 50},
)
6 changes: 6 additions & 0 deletions synapse/config/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ def read_config(self, config: JsonDict, **kwargs: Any) -> None:
"prevent_media_downloads_from", []
)

self.unused_expiration_time = self.parse_duration(
config.get("unused_expiration_time", "24h")
)

self.max_pending_media_uploads = config.get("max_pending_media_uploads", 5)

self.media_store_path = self.ensure_directory(
config.get("media_store_path", "media_store")
)
Expand Down
6 changes: 6 additions & 0 deletions synapse/media/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@
"audio/x-flac",
]

# Default timeout_ms for download and thumbnail requests
DEFAULT_MAX_TIMEOUT_MS = 20_000

# Maximum allowed timeout_ms for download and thumbnail requests
MAXIMUM_ALLOWED_MAX_TIMEOUT_MS = 60_000


def respond_404(request: SynapseRequest) -> None:
assert request.path is not None
Expand Down
Loading
Loading