matrix-synapse 1.139.2__cp39-abi3-manylinux_2_28_aarch64.whl → 1.140.0rc1__cp39-abi3-manylinux_2_28_aarch64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of matrix-synapse might be problematic. Click here for more details.
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/METADATA +5 -3
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/RECORD +157 -154
- synapse/_scripts/generate_workers_map.py +6 -1
- synapse/_scripts/synapse_port_db.py +0 -2
- synapse/_scripts/update_synapse_database.py +1 -6
- synapse/api/auth/base.py +1 -3
- synapse/api/auth/mas.py +6 -8
- synapse/api/auth/msc3861_delegated.py +6 -8
- synapse/api/errors.py +3 -0
- synapse/app/_base.py +101 -39
- synapse/app/admin_cmd.py +2 -4
- synapse/app/appservice.py +1 -1
- synapse/app/client_reader.py +1 -1
- synapse/app/event_creator.py +1 -1
- synapse/app/federation_reader.py +1 -1
- synapse/app/federation_sender.py +1 -1
- synapse/app/frontend_proxy.py +1 -1
- synapse/app/generic_worker.py +17 -11
- synapse/app/homeserver.py +85 -47
- synapse/app/media_repository.py +1 -1
- synapse/app/phone_stats_home.py +16 -14
- synapse/app/pusher.py +1 -1
- synapse/app/synchrotron.py +1 -1
- synapse/app/user_dir.py +1 -1
- synapse/appservice/__init__.py +29 -2
- synapse/appservice/scheduler.py +8 -8
- synapse/config/_base.py +32 -14
- synapse/config/_base.pyi +5 -3
- synapse/config/experimental.py +3 -0
- synapse/config/homeserver.py +27 -1
- synapse/config/logger.py +3 -4
- synapse/config/matrixrtc.py +67 -0
- synapse/crypto/keyring.py +18 -4
- synapse/events/auto_accept_invites.py +0 -1
- synapse/federation/federation_client.py +39 -0
- synapse/federation/federation_server.py +1 -1
- synapse/federation/send_queue.py +3 -0
- synapse/federation/sender/__init__.py +24 -8
- synapse/federation/sender/per_destination_queue.py +31 -8
- synapse/federation/sender/transaction_manager.py +12 -0
- synapse/federation/transport/client.py +29 -0
- synapse/handlers/account_validity.py +2 -4
- synapse/handlers/appservice.py +5 -7
- synapse/handlers/deactivate_account.py +2 -3
- synapse/handlers/delayed_events.py +10 -13
- synapse/handlers/device.py +14 -14
- synapse/handlers/e2e_keys.py +4 -3
- synapse/handlers/federation.py +7 -11
- synapse/handlers/federation_event.py +5 -6
- synapse/handlers/message.py +16 -10
- synapse/handlers/pagination.py +3 -7
- synapse/handlers/presence.py +21 -25
- synapse/handlers/profile.py +1 -1
- synapse/handlers/read_marker.py +3 -1
- synapse/handlers/register.py +8 -1
- synapse/handlers/room.py +13 -4
- synapse/handlers/room_member.py +11 -7
- synapse/handlers/room_policy.py +96 -2
- synapse/handlers/sso.py +1 -1
- synapse/handlers/stats.py +5 -3
- synapse/handlers/sync.py +20 -13
- synapse/handlers/typing.py +5 -10
- synapse/handlers/user_directory.py +12 -11
- synapse/handlers/worker_lock.py +19 -15
- synapse/http/client.py +18 -13
- synapse/http/federation/matrix_federation_agent.py +6 -1
- synapse/http/federation/well_known_resolver.py +3 -1
- synapse/http/matrixfederationclient.py +50 -11
- synapse/http/proxy.py +2 -2
- synapse/http/server.py +36 -2
- synapse/http/site.py +109 -17
- synapse/logging/context.py +165 -63
- synapse/logging/opentracing.py +30 -6
- synapse/logging/scopecontextmanager.py +161 -0
- synapse/media/_base.py +2 -1
- synapse/media/media_repository.py +20 -6
- synapse/media/url_previewer.py +5 -6
- synapse/metrics/_gc.py +3 -1
- synapse/metrics/background_process_metrics.py +128 -24
- synapse/metrics/common_usage_metrics.py +3 -5
- synapse/module_api/__init__.py +42 -5
- synapse/notifier.py +10 -3
- synapse/push/emailpusher.py +5 -4
- synapse/push/httppusher.py +6 -6
- synapse/push/pusherpool.py +3 -8
- synapse/replication/http/devices.py +0 -41
- synapse/replication/tcp/client.py +8 -5
- synapse/replication/tcp/handler.py +2 -3
- synapse/replication/tcp/protocol.py +14 -7
- synapse/replication/tcp/redis.py +16 -11
- synapse/replication/tcp/resource.py +5 -4
- synapse/replication/tcp/streams/__init__.py +2 -0
- synapse/res/providers.json +6 -5
- synapse/rest/__init__.py +2 -0
- synapse/rest/admin/__init__.py +4 -0
- synapse/rest/admin/events.py +69 -0
- synapse/rest/admin/media.py +70 -2
- synapse/rest/client/matrixrtc.py +52 -0
- synapse/rest/client/push_rule.py +1 -1
- synapse/rest/client/room.py +2 -3
- synapse/rest/client/sync.py +1 -0
- synapse/rest/client/transactions.py +1 -1
- synapse/server.py +271 -38
- synapse/server_notices/server_notices_manager.py +1 -0
- synapse/state/__init__.py +4 -1
- synapse/storage/_base.py +1 -1
- synapse/storage/background_updates.py +8 -3
- synapse/storage/controllers/persist_events.py +4 -3
- synapse/storage/controllers/purge_events.py +2 -3
- synapse/storage/controllers/state.py +5 -5
- synapse/storage/database.py +12 -7
- synapse/storage/databases/main/__init__.py +7 -2
- synapse/storage/databases/main/cache.py +4 -3
- synapse/storage/databases/main/censor_events.py +1 -1
- synapse/storage/databases/main/client_ips.py +9 -8
- synapse/storage/databases/main/deviceinbox.py +7 -6
- synapse/storage/databases/main/devices.py +4 -4
- synapse/storage/databases/main/end_to_end_keys.py +6 -3
- synapse/storage/databases/main/event_federation.py +7 -6
- synapse/storage/databases/main/event_push_actions.py +13 -13
- synapse/storage/databases/main/events_bg_updates.py +1 -1
- synapse/storage/databases/main/events_worker.py +6 -8
- synapse/storage/databases/main/lock.py +17 -13
- synapse/storage/databases/main/media_repository.py +2 -2
- synapse/storage/databases/main/metrics.py +6 -6
- synapse/storage/databases/main/monthly_active_users.py +3 -4
- synapse/storage/databases/main/receipts.py +1 -1
- synapse/storage/databases/main/registration.py +18 -19
- synapse/storage/databases/main/roommember.py +1 -1
- synapse/storage/databases/main/session.py +3 -3
- synapse/storage/databases/main/sliding_sync.py +2 -2
- synapse/storage/databases/main/transactions.py +3 -3
- synapse/storage/databases/state/store.py +2 -0
- synapse/synapse_rust/http_client.pyi +4 -0
- synapse/synapse_rust.abi3.so +0 -0
- synapse/util/async_helpers.py +36 -24
- synapse/util/batching_queue.py +16 -6
- synapse/util/caches/__init__.py +1 -1
- synapse/util/caches/deferred_cache.py +4 -0
- synapse/util/caches/descriptors.py +14 -2
- synapse/util/caches/dictionary_cache.py +6 -1
- synapse/util/caches/expiringcache.py +16 -5
- synapse/util/caches/lrucache.py +14 -26
- synapse/util/caches/response_cache.py +11 -1
- synapse/util/clock.py +215 -39
- synapse/util/constants.py +2 -0
- synapse/util/daemonize.py +5 -1
- synapse/util/distributor.py +9 -5
- synapse/util/metrics.py +35 -6
- synapse/util/ratelimitutils.py +4 -1
- synapse/util/retryutils.py +7 -4
- synapse/util/task_scheduler.py +11 -14
- synapse/logging/filter.py +0 -38
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/AUTHORS.rst +0 -0
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/LICENSE-AGPL-3.0 +0 -0
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/LICENSE-COMMERCIAL +0 -0
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/WHEEL +0 -0
- {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/entry_points.txt +0 -0
|
@@ -157,7 +157,12 @@ def get_registered_paths_for_default(
|
|
|
157
157
|
# TODO We only do this to avoid an error, but don't need the database etc
|
|
158
158
|
hs.setup()
|
|
159
159
|
registered_paths = get_registered_paths_for_hs(hs)
|
|
160
|
-
|
|
160
|
+
# NOTE: a more robust implementation would properly shutdown/cleanup each server
|
|
161
|
+
# to avoid resource buildup.
|
|
162
|
+
# However, the call to `shutdown` is `async` so it would require additional complexity here.
|
|
163
|
+
# We are intentionally skipping this cleanup because this is a short-lived, one-off
|
|
164
|
+
# utility script where the simpler approach is sufficient and we shouldn't run into
|
|
165
|
+
# any resource buildup issues.
|
|
161
166
|
|
|
162
167
|
return registered_paths
|
|
163
168
|
|
|
@@ -98,7 +98,6 @@ from synapse.storage.databases.state.bg_updates import StateBackgroundUpdateStor
|
|
|
98
98
|
from synapse.storage.engines import create_engine
|
|
99
99
|
from synapse.storage.prepare_database import prepare_database
|
|
100
100
|
from synapse.types import ISynapseReactor
|
|
101
|
-
from synapse.util import SYNAPSE_VERSION
|
|
102
101
|
|
|
103
102
|
# Cast safety: Twisted does some naughty magic which replaces the
|
|
104
103
|
# twisted.internet.reactor module with a Reactor instance at runtime.
|
|
@@ -325,7 +324,6 @@ class MockHomeserver(HomeServer):
|
|
|
325
324
|
hostname=config.server.server_name,
|
|
326
325
|
config=config,
|
|
327
326
|
reactor=reactor,
|
|
328
|
-
version_string=f"Synapse/{SYNAPSE_VERSION}",
|
|
329
327
|
)
|
|
330
328
|
|
|
331
329
|
|
|
@@ -28,11 +28,9 @@ import yaml
|
|
|
28
28
|
from twisted.internet import defer, reactor as reactor_
|
|
29
29
|
|
|
30
30
|
from synapse.config.homeserver import HomeServerConfig
|
|
31
|
-
from synapse.metrics.background_process_metrics import run_as_background_process
|
|
32
31
|
from synapse.server import HomeServer
|
|
33
32
|
from synapse.storage import DataStore
|
|
34
33
|
from synapse.types import ISynapseReactor
|
|
35
|
-
from synapse.util import SYNAPSE_VERSION
|
|
36
34
|
|
|
37
35
|
# Cast safety: Twisted does some naughty magic which replaces the
|
|
38
36
|
# twisted.internet.reactor module with a Reactor instance at runtime.
|
|
@@ -48,12 +46,10 @@ class MockHomeserver(HomeServer):
|
|
|
48
46
|
hostname=config.server.server_name,
|
|
49
47
|
config=config,
|
|
50
48
|
reactor=reactor,
|
|
51
|
-
version_string=f"Synapse/{SYNAPSE_VERSION}",
|
|
52
49
|
)
|
|
53
50
|
|
|
54
51
|
|
|
55
52
|
def run_background_updates(hs: HomeServer) -> None:
|
|
56
|
-
server_name = hs.hostname
|
|
57
53
|
main = hs.get_datastores().main
|
|
58
54
|
state = hs.get_datastores().state
|
|
59
55
|
|
|
@@ -67,9 +63,8 @@ def run_background_updates(hs: HomeServer) -> None:
|
|
|
67
63
|
def run() -> None:
|
|
68
64
|
# Apply all background updates on the database.
|
|
69
65
|
defer.ensureDeferred(
|
|
70
|
-
run_as_background_process(
|
|
66
|
+
hs.run_as_background_process(
|
|
71
67
|
"background_updates",
|
|
72
|
-
server_name,
|
|
73
68
|
run_background_updates,
|
|
74
69
|
)
|
|
75
70
|
)
|
synapse/api/auth/base.py
CHANGED
|
@@ -354,12 +354,10 @@ class BaseAuth:
|
|
|
354
354
|
effective_user_id, effective_device_id
|
|
355
355
|
)
|
|
356
356
|
if device_opt is None:
|
|
357
|
-
# For now, use 400 M_EXCLUSIVE if the device doesn't exist.
|
|
358
|
-
# This is an open thread of discussion on MSC3202 as of 2021-12-09.
|
|
359
357
|
raise AuthError(
|
|
360
358
|
400,
|
|
361
359
|
f"Application service trying to use a device that doesn't exist ('{effective_device_id}' for {effective_user_id})",
|
|
362
|
-
Codes.
|
|
360
|
+
Codes.UNKNOWN_DEVICE,
|
|
363
361
|
)
|
|
364
362
|
|
|
365
363
|
return create_requester(
|
synapse/api/auth/mas.py
CHANGED
|
@@ -33,7 +33,6 @@ from synapse.api.errors import (
|
|
|
33
33
|
UnrecognizedRequestError,
|
|
34
34
|
)
|
|
35
35
|
from synapse.http.site import SynapseRequest
|
|
36
|
-
from synapse.logging.context import PreserveLoggingContext
|
|
37
36
|
from synapse.logging.opentracing import (
|
|
38
37
|
active_span,
|
|
39
38
|
force_tracing,
|
|
@@ -229,13 +228,12 @@ class MasDelegatedAuth(BaseAuth):
|
|
|
229
228
|
try:
|
|
230
229
|
with start_active_span("mas-introspect-token"):
|
|
231
230
|
inject_request_headers(raw_headers)
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
)
|
|
231
|
+
resp_body = await self._rust_http_client.post(
|
|
232
|
+
url=self._introspection_endpoint,
|
|
233
|
+
response_limit=1 * 1024 * 1024,
|
|
234
|
+
headers=raw_headers,
|
|
235
|
+
request_body=body,
|
|
236
|
+
)
|
|
239
237
|
except HttpResponseException as e:
|
|
240
238
|
end_time = self._clock.time()
|
|
241
239
|
introspection_response_timer.labels(
|
|
@@ -38,7 +38,6 @@ from synapse.api.errors import (
|
|
|
38
38
|
UnrecognizedRequestError,
|
|
39
39
|
)
|
|
40
40
|
from synapse.http.site import SynapseRequest
|
|
41
|
-
from synapse.logging.context import PreserveLoggingContext
|
|
42
41
|
from synapse.logging.opentracing import (
|
|
43
42
|
active_span,
|
|
44
43
|
force_tracing,
|
|
@@ -327,13 +326,12 @@ class MSC3861DelegatedAuth(BaseAuth):
|
|
|
327
326
|
try:
|
|
328
327
|
with start_active_span("mas-introspect-token"):
|
|
329
328
|
inject_request_headers(raw_headers)
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
)
|
|
329
|
+
resp_body = await self._rust_http_client.post(
|
|
330
|
+
url=uri,
|
|
331
|
+
response_limit=1 * 1024 * 1024,
|
|
332
|
+
headers=raw_headers,
|
|
333
|
+
request_body=body,
|
|
334
|
+
)
|
|
337
335
|
except HttpResponseException as e:
|
|
338
336
|
end_time = self._clock.time()
|
|
339
337
|
introspection_response_timer.labels(
|
synapse/api/errors.py
CHANGED
|
@@ -149,6 +149,9 @@ class Codes(str, Enum):
|
|
|
149
149
|
)
|
|
150
150
|
MSC4306_NOT_IN_THREAD = "IO.ELEMENT.MSC4306.M_NOT_IN_THREAD"
|
|
151
151
|
|
|
152
|
+
# Part of MSC4326
|
|
153
|
+
UNKNOWN_DEVICE = "ORG.MATRIX.MSC4326.M_UNKNOWN_DEVICE"
|
|
154
|
+
|
|
152
155
|
|
|
153
156
|
class CodeMessageException(RuntimeError):
|
|
154
157
|
"""An exception with integer code, a message string attributes and optional headers.
|
synapse/app/_base.py
CHANGED
|
@@ -28,6 +28,7 @@ import sys
|
|
|
28
28
|
import traceback
|
|
29
29
|
import warnings
|
|
30
30
|
from textwrap import indent
|
|
31
|
+
from threading import Thread
|
|
31
32
|
from typing import (
|
|
32
33
|
TYPE_CHECKING,
|
|
33
34
|
Any,
|
|
@@ -40,6 +41,7 @@ from typing import (
|
|
|
40
41
|
Tuple,
|
|
41
42
|
cast,
|
|
42
43
|
)
|
|
44
|
+
from wsgiref.simple_server import WSGIServer
|
|
43
45
|
|
|
44
46
|
from cryptography.utils import CryptographyDeprecationWarning
|
|
45
47
|
from typing_extensions import ParamSpec
|
|
@@ -73,7 +75,6 @@ from synapse.events.presence_router import load_legacy_presence_router
|
|
|
73
75
|
from synapse.handlers.auth import load_legacy_password_auth_providers
|
|
74
76
|
from synapse.http.site import SynapseSite
|
|
75
77
|
from synapse.logging.context import LoggingContext, PreserveLoggingContext
|
|
76
|
-
from synapse.logging.opentracing import init_tracer
|
|
77
78
|
from synapse.metrics import install_gc_manager, register_threadpool
|
|
78
79
|
from synapse.metrics.background_process_metrics import run_as_background_process
|
|
79
80
|
from synapse.metrics.jemalloc import setup_jemalloc_stats
|
|
@@ -98,22 +99,47 @@ reactor = cast(ISynapseReactor, _reactor)
|
|
|
98
99
|
|
|
99
100
|
logger = logging.getLogger(__name__)
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
102
|
+
_instance_id_to_sighup_callbacks_map: Dict[
|
|
103
|
+
str, List[Tuple[Callable[..., None], Tuple[object, ...], Dict[str, object]]]
|
|
104
|
+
] = {}
|
|
105
|
+
"""
|
|
106
|
+
Map from homeserver instance_id to a list of callbacks.
|
|
107
|
+
|
|
108
|
+
We use `instance_id` instead of `server_name` because it's possible to have multiple
|
|
109
|
+
workers running in the same process with the same `server_name`.
|
|
110
|
+
"""
|
|
105
111
|
P = ParamSpec("P")
|
|
106
112
|
|
|
107
113
|
|
|
108
|
-
def register_sighup(
|
|
114
|
+
def register_sighup(
|
|
115
|
+
homeserver_instance_id: str,
|
|
116
|
+
func: Callable[P, None],
|
|
117
|
+
*args: P.args,
|
|
118
|
+
**kwargs: P.kwargs,
|
|
119
|
+
) -> None:
|
|
109
120
|
"""
|
|
110
121
|
Register a function to be called when a SIGHUP occurs.
|
|
111
122
|
|
|
112
123
|
Args:
|
|
124
|
+
homeserver_instance_id: The unique ID for this Synapse process instance
|
|
125
|
+
(`hs.get_instance_id()`) that this hook is associated with.
|
|
113
126
|
func: Function to be called when sent a SIGHUP signal.
|
|
114
127
|
*args, **kwargs: args and kwargs to be passed to the target function.
|
|
115
128
|
"""
|
|
116
|
-
|
|
129
|
+
|
|
130
|
+
_instance_id_to_sighup_callbacks_map.setdefault(homeserver_instance_id, []).append(
|
|
131
|
+
(func, args, kwargs)
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def unregister_sighups(instance_id: str) -> None:
|
|
136
|
+
"""
|
|
137
|
+
Unregister all sighup functions associated with this Synapse instance.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
instance_id: Unique ID for this Synapse process instance.
|
|
141
|
+
"""
|
|
142
|
+
_instance_id_to_sighup_callbacks_map.pop(instance_id, [])
|
|
117
143
|
|
|
118
144
|
|
|
119
145
|
def start_worker_reactor(
|
|
@@ -282,7 +308,9 @@ def register_start(
|
|
|
282
308
|
clock.call_when_running(lambda: defer.ensureDeferred(wrapper()))
|
|
283
309
|
|
|
284
310
|
|
|
285
|
-
def listen_metrics(
|
|
311
|
+
def listen_metrics(
|
|
312
|
+
bind_addresses: StrCollection, port: int
|
|
313
|
+
) -> List[Tuple[WSGIServer, Thread]]:
|
|
286
314
|
"""
|
|
287
315
|
Start Prometheus metrics server.
|
|
288
316
|
|
|
@@ -295,14 +323,22 @@ def listen_metrics(bind_addresses: StrCollection, port: int) -> None:
|
|
|
295
323
|
bytecode at a time), this still works because the metrics thread can preempt the
|
|
296
324
|
Twisted reactor thread between bytecode boundaries and the metrics thread gets
|
|
297
325
|
scheduled with roughly equal priority to the Twisted reactor thread.
|
|
326
|
+
|
|
327
|
+
Returns:
|
|
328
|
+
List of WSGIServer with the thread they are running on.
|
|
298
329
|
"""
|
|
299
330
|
from prometheus_client import start_http_server as start_http_server_prometheus
|
|
300
331
|
|
|
301
332
|
from synapse.metrics import RegistryProxy
|
|
302
333
|
|
|
334
|
+
servers: List[Tuple[WSGIServer, Thread]] = []
|
|
303
335
|
for host in bind_addresses:
|
|
304
336
|
logger.info("Starting metrics listener on %s:%d", host, port)
|
|
305
|
-
|
|
337
|
+
server, thread = start_http_server_prometheus(
|
|
338
|
+
port, addr=host, registry=RegistryProxy
|
|
339
|
+
)
|
|
340
|
+
servers.append((server, thread))
|
|
341
|
+
return servers
|
|
306
342
|
|
|
307
343
|
|
|
308
344
|
def listen_manhole(
|
|
@@ -310,7 +346,7 @@ def listen_manhole(
|
|
|
310
346
|
port: int,
|
|
311
347
|
manhole_settings: ManholeConfig,
|
|
312
348
|
manhole_globals: dict,
|
|
313
|
-
) ->
|
|
349
|
+
) -> List[Port]:
|
|
314
350
|
# twisted.conch.manhole 21.1.0 uses "int_from_bytes", which produces a confusing
|
|
315
351
|
# warning. It's fixed by https://github.com/twisted/twisted/pull/1522), so
|
|
316
352
|
# suppress the warning for now.
|
|
@@ -322,7 +358,7 @@ def listen_manhole(
|
|
|
322
358
|
|
|
323
359
|
from synapse.util.manhole import manhole
|
|
324
360
|
|
|
325
|
-
listen_tcp(
|
|
361
|
+
return listen_tcp(
|
|
326
362
|
bind_addresses,
|
|
327
363
|
port,
|
|
328
364
|
manhole(settings=manhole_settings, globals=manhole_globals),
|
|
@@ -385,17 +421,26 @@ def listen_http(
|
|
|
385
421
|
context_factory: Optional[IOpenSSLContextFactory],
|
|
386
422
|
reactor: ISynapseReactor = reactor,
|
|
387
423
|
) -> List[Port]:
|
|
424
|
+
"""
|
|
425
|
+
Args:
|
|
426
|
+
listener_config: TODO
|
|
427
|
+
root_resource: TODO
|
|
428
|
+
version_string: A string to present for the Server header
|
|
429
|
+
max_request_body_size: TODO
|
|
430
|
+
context_factory: TODO
|
|
431
|
+
reactor: TODO
|
|
432
|
+
"""
|
|
388
433
|
assert listener_config.http_options is not None
|
|
389
434
|
|
|
390
435
|
site_tag = listener_config.get_site_tag()
|
|
391
436
|
|
|
392
437
|
site = SynapseSite(
|
|
393
|
-
"synapse.access.%s.%s"
|
|
438
|
+
logger_name="synapse.access.%s.%s"
|
|
394
439
|
% ("https" if listener_config.is_tls() else "http", site_tag),
|
|
395
|
-
site_tag,
|
|
396
|
-
listener_config,
|
|
397
|
-
root_resource,
|
|
398
|
-
version_string,
|
|
440
|
+
site_tag=site_tag,
|
|
441
|
+
config=listener_config,
|
|
442
|
+
resource=root_resource,
|
|
443
|
+
server_version_string=version_string,
|
|
399
444
|
max_request_body_size=max_request_body_size,
|
|
400
445
|
reactor=reactor,
|
|
401
446
|
hs=hs,
|
|
@@ -499,7 +544,7 @@ def refresh_certificate(hs: "HomeServer") -> None:
|
|
|
499
544
|
logger.info("Context factories updated.")
|
|
500
545
|
|
|
501
546
|
|
|
502
|
-
async def start(hs: "HomeServer") -> None:
|
|
547
|
+
async def start(hs: "HomeServer", freeze: bool = True) -> None:
|
|
503
548
|
"""
|
|
504
549
|
Start a Synapse server or worker.
|
|
505
550
|
|
|
@@ -510,6 +555,11 @@ async def start(hs: "HomeServer") -> None:
|
|
|
510
555
|
|
|
511
556
|
Args:
|
|
512
557
|
hs: homeserver instance
|
|
558
|
+
freeze: whether to freeze the homeserver base objects in the garbage collector.
|
|
559
|
+
May improve garbage collection performance by marking objects with an effectively
|
|
560
|
+
static lifetime as frozen so they don't need to be considered for cleanup.
|
|
561
|
+
If you ever want to `shutdown` the homeserver, this needs to be
|
|
562
|
+
False otherwise the homeserver cannot be garbage collected after `shutdown`.
|
|
513
563
|
"""
|
|
514
564
|
server_name = hs.hostname
|
|
515
565
|
reactor = hs.get_reactor()
|
|
@@ -542,12 +592,17 @@ async def start(hs: "HomeServer") -> None:
|
|
|
542
592
|
# we're not using systemd.
|
|
543
593
|
sdnotify(b"RELOADING=1")
|
|
544
594
|
|
|
545
|
-
|
|
546
|
-
|
|
595
|
+
for sighup_callbacks in _instance_id_to_sighup_callbacks_map.values():
|
|
596
|
+
for func, args, kwargs in sighup_callbacks:
|
|
597
|
+
func(*args, **kwargs)
|
|
547
598
|
|
|
548
599
|
sdnotify(b"READY=1")
|
|
549
600
|
|
|
550
|
-
|
|
601
|
+
# It's okay to ignore the linter error here and call
|
|
602
|
+
# `run_as_background_process` directly because `_handle_sighup` operates
|
|
603
|
+
# outside of the scope of a specific `HomeServer` instance and holds no
|
|
604
|
+
# references to it which would prevent a clean shutdown.
|
|
605
|
+
return run_as_background_process( # type: ignore[untracked-background-process]
|
|
551
606
|
"sighup",
|
|
552
607
|
server_name,
|
|
553
608
|
_handle_sighup,
|
|
@@ -565,8 +620,8 @@ async def start(hs: "HomeServer") -> None:
|
|
|
565
620
|
|
|
566
621
|
signal.signal(signal.SIGHUP, run_sighup)
|
|
567
622
|
|
|
568
|
-
register_sighup(refresh_certificate, hs)
|
|
569
|
-
register_sighup(reload_cache_config, hs.config)
|
|
623
|
+
register_sighup(hs.get_instance_id(), refresh_certificate, hs)
|
|
624
|
+
register_sighup(hs.get_instance_id(), reload_cache_config, hs.config)
|
|
570
625
|
|
|
571
626
|
# Apply the cache config.
|
|
572
627
|
hs.config.caches.resize_all_caches()
|
|
@@ -574,9 +629,6 @@ async def start(hs: "HomeServer") -> None:
|
|
|
574
629
|
# Load the certificate from disk.
|
|
575
630
|
refresh_certificate(hs)
|
|
576
631
|
|
|
577
|
-
# Start the tracer
|
|
578
|
-
init_tracer(hs) # noqa
|
|
579
|
-
|
|
580
632
|
# Instantiate the modules so they can register their web resources to the module API
|
|
581
633
|
# before we start the listeners.
|
|
582
634
|
module_api = hs.get_module_api()
|
|
@@ -603,11 +655,15 @@ async def start(hs: "HomeServer") -> None:
|
|
|
603
655
|
hs.get_pusherpool().start()
|
|
604
656
|
|
|
605
657
|
def log_shutdown() -> None:
|
|
606
|
-
with LoggingContext("log_shutdown"):
|
|
658
|
+
with LoggingContext(name="log_shutdown", server_name=server_name):
|
|
607
659
|
logger.info("Shutting down...")
|
|
608
660
|
|
|
609
661
|
# Log when we start the shut down process.
|
|
610
|
-
hs.
|
|
662
|
+
hs.register_sync_shutdown_handler(
|
|
663
|
+
phase="before",
|
|
664
|
+
eventType="shutdown",
|
|
665
|
+
shutdown_func=log_shutdown,
|
|
666
|
+
)
|
|
611
667
|
|
|
612
668
|
setup_sentry(hs)
|
|
613
669
|
setup_sdnotify(hs)
|
|
@@ -636,18 +692,24 @@ async def start(hs: "HomeServer") -> None:
|
|
|
636
692
|
# `REQUIRED_ON_BACKGROUND_TASK_STARTUP`
|
|
637
693
|
start_phone_stats_home(hs)
|
|
638
694
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
#
|
|
649
|
-
#
|
|
650
|
-
|
|
695
|
+
if freeze:
|
|
696
|
+
# We now freeze all allocated objects in the hopes that (almost)
|
|
697
|
+
# everything currently allocated are things that will be used for the
|
|
698
|
+
# rest of time. Doing so means less work each GC (hopefully).
|
|
699
|
+
#
|
|
700
|
+
# Note that freezing the homeserver object means that it won't be able to be
|
|
701
|
+
# garbage collected in the case of attempting an in-memory `shutdown`. This only
|
|
702
|
+
# needs to be considered if such a case is desirable. Exiting the entire Python
|
|
703
|
+
# process will function expectedly either way.
|
|
704
|
+
#
|
|
705
|
+
# PyPy does not (yet?) implement gc.freeze()
|
|
706
|
+
if hasattr(gc, "freeze"):
|
|
707
|
+
gc.collect()
|
|
708
|
+
gc.freeze()
|
|
709
|
+
|
|
710
|
+
# Speed up process exit by freezing all allocated objects. This moves everything
|
|
711
|
+
# into the permanent generation and excludes them from the final GC.
|
|
712
|
+
atexit.register(gc.freeze)
|
|
651
713
|
|
|
652
714
|
|
|
653
715
|
def reload_cache_config(config: HomeServerConfig) -> None:
|
synapse/app/admin_cmd.py
CHANGED
|
@@ -65,7 +65,6 @@ from synapse.storage.databases.main.stream import StreamWorkerStore
|
|
|
65
65
|
from synapse.storage.databases.main.tags import TagsWorkerStore
|
|
66
66
|
from synapse.storage.databases.main.user_erasure_store import UserErasureWorkerStore
|
|
67
67
|
from synapse.types import JsonMapping, StateMap
|
|
68
|
-
from synapse.util import SYNAPSE_VERSION
|
|
69
68
|
from synapse.util.logcontext import LoggingContext
|
|
70
69
|
|
|
71
70
|
logger = logging.getLogger("synapse.app.admin_cmd")
|
|
@@ -316,7 +315,6 @@ def start(config: HomeServerConfig, args: argparse.Namespace) -> None:
|
|
|
316
315
|
ss = AdminCmdServer(
|
|
317
316
|
config.server.server_name,
|
|
318
317
|
config=config,
|
|
319
|
-
version_string=f"Synapse/{SYNAPSE_VERSION}",
|
|
320
318
|
)
|
|
321
319
|
|
|
322
320
|
setup_logging(ss, config, use_worker_options=True)
|
|
@@ -329,7 +327,7 @@ def start(config: HomeServerConfig, args: argparse.Namespace) -> None:
|
|
|
329
327
|
# command.
|
|
330
328
|
|
|
331
329
|
async def run() -> None:
|
|
332
|
-
with LoggingContext(name="command"):
|
|
330
|
+
with LoggingContext(name="command", server_name=config.server.server_name):
|
|
333
331
|
await _base.start(ss)
|
|
334
332
|
await args.func(ss, args)
|
|
335
333
|
|
|
@@ -342,5 +340,5 @@ def start(config: HomeServerConfig, args: argparse.Namespace) -> None:
|
|
|
342
340
|
|
|
343
341
|
if __name__ == "__main__":
|
|
344
342
|
homeserver_config, args = load_config(sys.argv[1:])
|
|
345
|
-
with LoggingContext(name="main"):
|
|
343
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
346
344
|
start(homeserver_config, args)
|
synapse/app/appservice.py
CHANGED
|
@@ -27,7 +27,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
27
27
|
|
|
28
28
|
def main() -> None:
|
|
29
29
|
homeserver_config = load_config(sys.argv[1:])
|
|
30
|
-
with LoggingContext(name="main"):
|
|
30
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
31
31
|
start(homeserver_config)
|
|
32
32
|
|
|
33
33
|
|
synapse/app/client_reader.py
CHANGED
|
@@ -27,7 +27,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
27
27
|
|
|
28
28
|
def main() -> None:
|
|
29
29
|
homeserver_config = load_config(sys.argv[1:])
|
|
30
|
-
with LoggingContext(name="main"):
|
|
30
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
31
31
|
start(homeserver_config)
|
|
32
32
|
|
|
33
33
|
|
synapse/app/event_creator.py
CHANGED
|
@@ -26,7 +26,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
26
26
|
|
|
27
27
|
def main() -> None:
|
|
28
28
|
homeserver_config = load_config(sys.argv[1:])
|
|
29
|
-
with LoggingContext(name="main"):
|
|
29
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
30
30
|
start(homeserver_config)
|
|
31
31
|
|
|
32
32
|
|
synapse/app/federation_reader.py
CHANGED
|
@@ -27,7 +27,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
27
27
|
|
|
28
28
|
def main() -> None:
|
|
29
29
|
homeserver_config = load_config(sys.argv[1:])
|
|
30
|
-
with LoggingContext(name="main"):
|
|
30
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
31
31
|
start(homeserver_config)
|
|
32
32
|
|
|
33
33
|
|
synapse/app/federation_sender.py
CHANGED
|
@@ -27,7 +27,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
27
27
|
|
|
28
28
|
def main() -> None:
|
|
29
29
|
homeserver_config = load_config(sys.argv[1:])
|
|
30
|
-
with LoggingContext(name="main"):
|
|
30
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
31
31
|
start(homeserver_config)
|
|
32
32
|
|
|
33
33
|
|
synapse/app/frontend_proxy.py
CHANGED
|
@@ -27,7 +27,7 @@ from synapse.util.logcontext import LoggingContext
|
|
|
27
27
|
|
|
28
28
|
def main() -> None:
|
|
29
29
|
homeserver_config = load_config(sys.argv[1:])
|
|
30
|
-
with LoggingContext(name="main"):
|
|
30
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
31
31
|
start(homeserver_config)
|
|
32
32
|
|
|
33
33
|
|
synapse/app/generic_worker.py
CHANGED
|
@@ -49,6 +49,7 @@ from synapse.config.server import ListenerConfig, TCPListenerConfig
|
|
|
49
49
|
from synapse.federation.transport.server import TransportLayerServer
|
|
50
50
|
from synapse.http.server import JsonResource, OptionsResource
|
|
51
51
|
from synapse.logging.context import LoggingContext
|
|
52
|
+
from synapse.logging.opentracing import init_tracer
|
|
52
53
|
from synapse.metrics import METRICS_PREFIX, MetricsResource, RegistryProxy
|
|
53
54
|
from synapse.replication.http import REPLICATION_PREFIX, ReplicationRestResource
|
|
54
55
|
from synapse.rest import ClientRestResource, admin
|
|
@@ -111,7 +112,6 @@ from synapse.storage.databases.main.transactions import TransactionWorkerStore
|
|
|
111
112
|
from synapse.storage.databases.main.ui_auth import UIAuthWorkerStore
|
|
112
113
|
from synapse.storage.databases.main.user_directory import UserDirectoryStore
|
|
113
114
|
from synapse.storage.databases.main.user_erasure_store import UserErasureWorkerStore
|
|
114
|
-
from synapse.util import SYNAPSE_VERSION
|
|
115
115
|
from synapse.util.httpresourcetree import create_resource_tree
|
|
116
116
|
|
|
117
117
|
logger = logging.getLogger("synapse.app.generic_worker")
|
|
@@ -277,11 +277,13 @@ class GenericWorkerServer(HomeServer):
|
|
|
277
277
|
self._listen_http(listener)
|
|
278
278
|
elif listener.type == "manhole":
|
|
279
279
|
if isinstance(listener, TCPListenerConfig):
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
280
|
+
self._listening_services.extend(
|
|
281
|
+
_base.listen_manhole(
|
|
282
|
+
listener.bind_addresses,
|
|
283
|
+
listener.port,
|
|
284
|
+
manhole_settings=self.config.server.manhole_settings,
|
|
285
|
+
manhole_globals={"hs": self},
|
|
286
|
+
)
|
|
285
287
|
)
|
|
286
288
|
else:
|
|
287
289
|
raise ConfigError(
|
|
@@ -295,9 +297,11 @@ class GenericWorkerServer(HomeServer):
|
|
|
295
297
|
)
|
|
296
298
|
else:
|
|
297
299
|
if isinstance(listener, TCPListenerConfig):
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
300
|
+
self._metrics_listeners.extend(
|
|
301
|
+
_base.listen_metrics(
|
|
302
|
+
listener.bind_addresses,
|
|
303
|
+
listener.port,
|
|
304
|
+
)
|
|
301
305
|
)
|
|
302
306
|
else:
|
|
303
307
|
raise ConfigError(
|
|
@@ -354,11 +358,13 @@ def start(config: HomeServerConfig) -> None:
|
|
|
354
358
|
hs = GenericWorkerServer(
|
|
355
359
|
config.server.server_name,
|
|
356
360
|
config=config,
|
|
357
|
-
version_string=f"Synapse/{SYNAPSE_VERSION}",
|
|
358
361
|
)
|
|
359
362
|
|
|
360
363
|
setup_logging(hs, config, use_worker_options=True)
|
|
361
364
|
|
|
365
|
+
# Start the tracer
|
|
366
|
+
init_tracer(hs) # noqa
|
|
367
|
+
|
|
362
368
|
try:
|
|
363
369
|
hs.setup()
|
|
364
370
|
|
|
@@ -382,7 +388,7 @@ def start(config: HomeServerConfig) -> None:
|
|
|
382
388
|
|
|
383
389
|
def main() -> None:
|
|
384
390
|
homeserver_config = load_config(sys.argv[1:])
|
|
385
|
-
with LoggingContext(name="main"):
|
|
391
|
+
with LoggingContext(name="main", server_name=homeserver_config.server.server_name):
|
|
386
392
|
start(homeserver_config)
|
|
387
393
|
|
|
388
394
|
|