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

Commit e8ed9a6

Browse files
committed
Merge commit '8238b55e0' into anoa/dinsic_release_1_21_x
* commit '8238b55e0': Update description of server_name config option (#8415) Discard an empty upload_name before persisting an uploaded file (#7905) Don't table scan events on worker startup (#8419) Mypy fixes for `synapse.handlers.federation` (#8422)
2 parents ab26b58 + 8238b55 commit e8ed9a6

File tree

15 files changed

+107
-23
lines changed

15 files changed

+107
-23
lines changed

changelog.d/7905.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a longstanding bug when storing a media file with an empty `upload_name`.

changelog.d/8415.doc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Improve description of `server_name` config option in `homserver.yaml`.

changelog.d/8419.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add experimental support for sharding event persister.

changelog.d/8422.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Typing fixes for `synapse.handlers.federation`.

docs/sample_config.yaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,23 @@
3333

3434
## Server ##
3535

36-
# The domain name of the server, with optional explicit port.
37-
# This is used by remote servers to connect to this server,
38-
# e.g. matrix.org, localhost:8080, etc.
39-
# This is also the last part of your UserID.
36+
# The public-facing domain of the server
37+
#
38+
# The server_name name will appear at the end of usernames and room addresses
39+
# created on this server. For example if the server_name was example.com,
40+
# usernames on this server would be in the format @user:example.com
41+
#
42+
# In most cases you should avoid using a matrix specific subdomain such as
43+
# matrix.example.com or synapse.example.com as the server_name for the same
44+
# reasons you wouldn't use user@email.example.com as your email address.
45+
# See https://github.com/matrix-org/synapse/blob/master/docs/delegate.md
46+
# for information on how to host Synapse on a subdomain while preserving
47+
# a clean server_name.
48+
#
49+
# The server_name cannot be changed later so it is important to
50+
# configure this correctly before you start Synapse. It should be all
51+
# lowercase and may contain an explicit port.
52+
# Examples: matrix.org, localhost:8080
4053
#
4154
server_name: "SERVERNAME"
4255

synapse/config/server.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,10 +647,23 @@ def generate_config_section(
647647
"""\
648648
## Server ##
649649
650-
# The domain name of the server, with optional explicit port.
651-
# This is used by remote servers to connect to this server,
652-
# e.g. matrix.org, localhost:8080, etc.
653-
# This is also the last part of your UserID.
650+
# The public-facing domain of the server
651+
#
652+
# The server_name name will appear at the end of usernames and room addresses
653+
# created on this server. For example if the server_name was example.com,
654+
# usernames on this server would be in the format @user:example.com
655+
#
656+
# In most cases you should avoid using a matrix specific subdomain such as
657+
# matrix.example.com or synapse.example.com as the server_name for the same
658+
# reasons you wouldn't use user@email.example.com as your email address.
659+
# See https://github.com/matrix-org/synapse/blob/master/docs/delegate.md
660+
# for information on how to host Synapse on a subdomain while preserving
661+
# a clean server_name.
662+
#
663+
# The server_name cannot be changed later so it is important to
664+
# configure this correctly before you start Synapse. It should be all
665+
# lowercase and may contain an explicit port.
666+
# Examples: matrix.org, localhost:8080
654667
#
655668
server_name: "%(server_name)s"
656669

synapse/federation/federation_client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@
2424
Dict,
2525
Iterable,
2626
List,
27+
Mapping,
2728
Optional,
2829
Sequence,
2930
Tuple,
3031
TypeVar,
32+
Union,
3133
)
3234

3335
from prometheus_client import Counter
@@ -501,7 +503,7 @@ async def make_membership_event(
501503
user_id: str,
502504
membership: str,
503505
content: dict,
504-
params: Dict[str, str],
506+
params: Optional[Mapping[str, Union[str, Iterable[str]]]],
505507
) -> Tuple[str, EventBase, RoomVersion]:
506508
"""
507509
Creates an m.room.member event, with context, without participating in the room.

synapse/handlers/federation.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ def __init__(self, hs):
155155
self._device_list_updater = hs.get_device_handler().device_list_updater
156156
self._maybe_store_room_on_invite = self.store.maybe_store_room_on_invite
157157

158-
# When joining a room we need to queue any events for that room up
159-
self.room_queues = {}
158+
# When joining a room we need to queue any events for that room up.
159+
# For each room, a list of (pdu, origin) tuples.
160+
self.room_queues = {} # type: Dict[str, List[Tuple[EventBase, str]]]
160161
self._room_pdu_linearizer = Linearizer("fed_room_pdu")
161162

162163
self.third_party_event_rules = hs.get_third_party_event_rules()
@@ -817,6 +818,9 @@ async def backfill(self, dest, room_id, limit, extremities):
817818
dest, room_id, limit=limit, extremities=extremities
818819
)
819820

821+
if not events:
822+
return []
823+
820824
# ideally we'd sanity check the events here for excess prev_events etc,
821825
# but it's hard to reject events at this point without completely
822826
# breaking backfill in the same way that it is currently broken by
@@ -2174,10 +2178,10 @@ async def _check_for_soft_fail(
21742178
# given state at the event. This should correctly handle cases
21752179
# like bans, especially with state res v2.
21762180

2177-
state_sets = await self.state_store.get_state_groups(
2181+
state_sets_d = await self.state_store.get_state_groups(
21782182
event.room_id, extrem_ids
21792183
)
2180-
state_sets = list(state_sets.values())
2184+
state_sets = list(state_sets_d.values()) # type: List[Iterable[EventBase]]
21812185
state_sets.append(state)
21822186
current_states = await self.state_handler.resolve_events(
21832187
room_version, state_sets, event
@@ -2968,6 +2972,7 @@ async def persist_events_and_notify(
29682972
)
29692973
return result["max_stream_id"]
29702974
else:
2975+
assert self.storage.persistence
29712976
max_stream_token = await self.storage.persistence.persist_events(
29722977
event_and_contexts, backfilled=backfilled
29732978
)

synapse/rest/media/v1/media_repository.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,23 +139,24 @@ def mark_recently_accessed(self, server_name, media_id):
139139
async def create_content(
140140
self,
141141
media_type: str,
142-
upload_name: str,
142+
upload_name: Optional[str],
143143
content: IO,
144144
content_length: int,
145145
auth_user: str,
146146
) -> str:
147147
"""Store uploaded content for a local user and return the mxc URL
148148
149149
Args:
150-
media_type: The content type of the file
151-
upload_name: The name of the file
150+
media_type: The content type of the file.
151+
upload_name: The name of the file, if provided.
152152
content: A file like object that is the content to store
153153
content_length: The length of the content
154154
auth_user: The user_id of the uploader
155155
156156
Returns:
157157
The mxc url of the stored content
158158
"""
159+
159160
media_id = random_string(24)
160161

161162
file_info = FileInfo(server_name=None, file_id=media_id)

synapse/rest/media/v1/upload_resource.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ async def _async_render_POST(self, request):
6363
msg="Invalid UTF-8 filename parameter: %r" % (upload_name), code=400
6464
)
6565

66+
# If the name is falsey (e.g. an empty byte string) ensure it is None.
67+
else:
68+
upload_name = None
69+
6670
headers = request.requestHeaders
6771

6872
if headers.hasHeader(b"Content-Type"):

0 commit comments

Comments
 (0)