matrix-synapse 1.139.2__cp39-abi3-macosx_11_0_arm64.whl → 1.140.0rc1__cp39-abi3-macosx_11_0_arm64.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.

Files changed (158) hide show
  1. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/METADATA +5 -3
  2. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/RECORD +157 -154
  3. synapse/_scripts/generate_workers_map.py +6 -1
  4. synapse/_scripts/synapse_port_db.py +0 -2
  5. synapse/_scripts/update_synapse_database.py +1 -6
  6. synapse/api/auth/base.py +1 -3
  7. synapse/api/auth/mas.py +6 -8
  8. synapse/api/auth/msc3861_delegated.py +6 -8
  9. synapse/api/errors.py +3 -0
  10. synapse/app/_base.py +101 -39
  11. synapse/app/admin_cmd.py +2 -4
  12. synapse/app/appservice.py +1 -1
  13. synapse/app/client_reader.py +1 -1
  14. synapse/app/event_creator.py +1 -1
  15. synapse/app/federation_reader.py +1 -1
  16. synapse/app/federation_sender.py +1 -1
  17. synapse/app/frontend_proxy.py +1 -1
  18. synapse/app/generic_worker.py +17 -11
  19. synapse/app/homeserver.py +85 -47
  20. synapse/app/media_repository.py +1 -1
  21. synapse/app/phone_stats_home.py +16 -14
  22. synapse/app/pusher.py +1 -1
  23. synapse/app/synchrotron.py +1 -1
  24. synapse/app/user_dir.py +1 -1
  25. synapse/appservice/__init__.py +29 -2
  26. synapse/appservice/scheduler.py +8 -8
  27. synapse/config/_base.py +32 -14
  28. synapse/config/_base.pyi +5 -3
  29. synapse/config/experimental.py +3 -0
  30. synapse/config/homeserver.py +27 -1
  31. synapse/config/logger.py +3 -4
  32. synapse/config/matrixrtc.py +67 -0
  33. synapse/crypto/keyring.py +18 -4
  34. synapse/events/auto_accept_invites.py +0 -1
  35. synapse/federation/federation_client.py +39 -0
  36. synapse/federation/federation_server.py +1 -1
  37. synapse/federation/send_queue.py +3 -0
  38. synapse/federation/sender/__init__.py +24 -8
  39. synapse/federation/sender/per_destination_queue.py +31 -8
  40. synapse/federation/sender/transaction_manager.py +12 -0
  41. synapse/federation/transport/client.py +29 -0
  42. synapse/handlers/account_validity.py +2 -4
  43. synapse/handlers/appservice.py +5 -7
  44. synapse/handlers/deactivate_account.py +2 -3
  45. synapse/handlers/delayed_events.py +10 -13
  46. synapse/handlers/device.py +14 -14
  47. synapse/handlers/e2e_keys.py +4 -3
  48. synapse/handlers/federation.py +7 -11
  49. synapse/handlers/federation_event.py +5 -6
  50. synapse/handlers/message.py +16 -10
  51. synapse/handlers/pagination.py +3 -7
  52. synapse/handlers/presence.py +21 -25
  53. synapse/handlers/profile.py +1 -1
  54. synapse/handlers/read_marker.py +3 -1
  55. synapse/handlers/register.py +8 -1
  56. synapse/handlers/room.py +13 -4
  57. synapse/handlers/room_member.py +11 -7
  58. synapse/handlers/room_policy.py +96 -2
  59. synapse/handlers/sso.py +1 -1
  60. synapse/handlers/stats.py +5 -3
  61. synapse/handlers/sync.py +20 -13
  62. synapse/handlers/typing.py +5 -10
  63. synapse/handlers/user_directory.py +12 -11
  64. synapse/handlers/worker_lock.py +19 -15
  65. synapse/http/client.py +18 -13
  66. synapse/http/federation/matrix_federation_agent.py +6 -1
  67. synapse/http/federation/well_known_resolver.py +3 -1
  68. synapse/http/matrixfederationclient.py +50 -11
  69. synapse/http/proxy.py +2 -2
  70. synapse/http/server.py +36 -2
  71. synapse/http/site.py +109 -17
  72. synapse/logging/context.py +165 -63
  73. synapse/logging/opentracing.py +30 -6
  74. synapse/logging/scopecontextmanager.py +161 -0
  75. synapse/media/_base.py +2 -1
  76. synapse/media/media_repository.py +20 -6
  77. synapse/media/url_previewer.py +5 -6
  78. synapse/metrics/_gc.py +3 -1
  79. synapse/metrics/background_process_metrics.py +128 -24
  80. synapse/metrics/common_usage_metrics.py +3 -5
  81. synapse/module_api/__init__.py +42 -5
  82. synapse/notifier.py +10 -3
  83. synapse/push/emailpusher.py +5 -4
  84. synapse/push/httppusher.py +6 -6
  85. synapse/push/pusherpool.py +3 -8
  86. synapse/replication/http/devices.py +0 -41
  87. synapse/replication/tcp/client.py +8 -5
  88. synapse/replication/tcp/handler.py +2 -3
  89. synapse/replication/tcp/protocol.py +14 -7
  90. synapse/replication/tcp/redis.py +16 -11
  91. synapse/replication/tcp/resource.py +5 -4
  92. synapse/replication/tcp/streams/__init__.py +2 -0
  93. synapse/res/providers.json +6 -5
  94. synapse/rest/__init__.py +2 -0
  95. synapse/rest/admin/__init__.py +4 -0
  96. synapse/rest/admin/events.py +69 -0
  97. synapse/rest/admin/media.py +70 -2
  98. synapse/rest/client/matrixrtc.py +52 -0
  99. synapse/rest/client/push_rule.py +1 -1
  100. synapse/rest/client/room.py +2 -3
  101. synapse/rest/client/sync.py +1 -0
  102. synapse/rest/client/transactions.py +1 -1
  103. synapse/server.py +271 -38
  104. synapse/server_notices/server_notices_manager.py +1 -0
  105. synapse/state/__init__.py +4 -1
  106. synapse/storage/_base.py +1 -1
  107. synapse/storage/background_updates.py +8 -3
  108. synapse/storage/controllers/persist_events.py +4 -3
  109. synapse/storage/controllers/purge_events.py +2 -3
  110. synapse/storage/controllers/state.py +5 -5
  111. synapse/storage/database.py +12 -7
  112. synapse/storage/databases/main/__init__.py +7 -2
  113. synapse/storage/databases/main/cache.py +4 -3
  114. synapse/storage/databases/main/censor_events.py +1 -1
  115. synapse/storage/databases/main/client_ips.py +9 -8
  116. synapse/storage/databases/main/deviceinbox.py +7 -6
  117. synapse/storage/databases/main/devices.py +4 -4
  118. synapse/storage/databases/main/end_to_end_keys.py +6 -3
  119. synapse/storage/databases/main/event_federation.py +7 -6
  120. synapse/storage/databases/main/event_push_actions.py +13 -13
  121. synapse/storage/databases/main/events_bg_updates.py +1 -1
  122. synapse/storage/databases/main/events_worker.py +6 -8
  123. synapse/storage/databases/main/lock.py +17 -13
  124. synapse/storage/databases/main/media_repository.py +2 -2
  125. synapse/storage/databases/main/metrics.py +6 -6
  126. synapse/storage/databases/main/monthly_active_users.py +3 -4
  127. synapse/storage/databases/main/receipts.py +1 -1
  128. synapse/storage/databases/main/registration.py +18 -19
  129. synapse/storage/databases/main/roommember.py +1 -1
  130. synapse/storage/databases/main/session.py +3 -3
  131. synapse/storage/databases/main/sliding_sync.py +2 -2
  132. synapse/storage/databases/main/transactions.py +3 -3
  133. synapse/storage/databases/state/store.py +2 -0
  134. synapse/synapse_rust/http_client.pyi +4 -0
  135. synapse/synapse_rust.abi3.so +0 -0
  136. synapse/util/async_helpers.py +36 -24
  137. synapse/util/batching_queue.py +16 -6
  138. synapse/util/caches/__init__.py +1 -1
  139. synapse/util/caches/deferred_cache.py +4 -0
  140. synapse/util/caches/descriptors.py +14 -2
  141. synapse/util/caches/dictionary_cache.py +6 -1
  142. synapse/util/caches/expiringcache.py +16 -5
  143. synapse/util/caches/lrucache.py +14 -26
  144. synapse/util/caches/response_cache.py +11 -1
  145. synapse/util/clock.py +215 -39
  146. synapse/util/constants.py +2 -0
  147. synapse/util/daemonize.py +5 -1
  148. synapse/util/distributor.py +9 -5
  149. synapse/util/metrics.py +35 -6
  150. synapse/util/ratelimitutils.py +4 -1
  151. synapse/util/retryutils.py +7 -4
  152. synapse/util/task_scheduler.py +11 -14
  153. synapse/logging/filter.py +0 -38
  154. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/AUTHORS.rst +0 -0
  155. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/LICENSE-AGPL-3.0 +0 -0
  156. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/LICENSE-COMMERCIAL +0 -0
  157. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/WHEEL +0 -0
  158. {matrix_synapse-1.139.2.dist-info → matrix_synapse-1.140.0rc1.dist-info}/entry_points.txt +0 -0
@@ -24,7 +24,6 @@ from types import TracebackType
24
24
  from typing import TYPE_CHECKING, Any, Optional, Type
25
25
 
26
26
  from synapse.api.errors import CodeMessageException
27
- from synapse.metrics.background_process_metrics import run_as_background_process
28
27
  from synapse.storage import DataStore
29
28
  from synapse.types import StrCollection
30
29
  from synapse.util.clock import Clock
@@ -32,6 +31,7 @@ from synapse.util.clock import Clock
32
31
  if TYPE_CHECKING:
33
32
  from synapse.notifier import Notifier
34
33
  from synapse.replication.tcp.handler import ReplicationCommandHandler
34
+ from synapse.server import HomeServer
35
35
 
36
36
  logger = logging.getLogger(__name__)
37
37
 
@@ -62,6 +62,7 @@ async def get_retry_limiter(
62
62
  *,
63
63
  destination: str,
64
64
  our_server_name: str,
65
+ hs: "HomeServer",
65
66
  clock: Clock,
66
67
  store: DataStore,
67
68
  ignore_backoff: bool = False,
@@ -124,6 +125,7 @@ async def get_retry_limiter(
124
125
  return RetryDestinationLimiter(
125
126
  destination=destination,
126
127
  our_server_name=our_server_name,
128
+ hs=hs,
127
129
  clock=clock,
128
130
  store=store,
129
131
  failure_ts=failure_ts,
@@ -163,6 +165,7 @@ class RetryDestinationLimiter:
163
165
  *,
164
166
  destination: str,
165
167
  our_server_name: str,
168
+ hs: "HomeServer",
166
169
  clock: Clock,
167
170
  store: DataStore,
168
171
  failure_ts: Optional[int],
@@ -181,6 +184,7 @@ class RetryDestinationLimiter:
181
184
  Args:
182
185
  destination
183
186
  our_server_name: Our homeserver name (used to label metrics) (`hs.hostname`)
187
+ hs: The homeserver instance
184
188
  clock
185
189
  store
186
190
  failure_ts: when this destination started failing (in ms since
@@ -197,6 +201,7 @@ class RetryDestinationLimiter:
197
201
  error code.
198
202
  """
199
203
  self.our_server_name = our_server_name
204
+ self.hs = hs
200
205
  self.clock = clock
201
206
  self.store = store
202
207
  self.destination = destination
@@ -331,6 +336,4 @@ class RetryDestinationLimiter:
331
336
  logger.exception("Failed to store destination_retry_timings")
332
337
 
333
338
  # we deliberately do this in the background.
334
- run_as_background_process(
335
- "store_retry_timings", self.our_server_name, store_retry_timings
336
- )
339
+ self.hs.run_as_background_process("store_retry_timings", store_retry_timings)
@@ -27,12 +27,11 @@ from twisted.python.failure import Failure
27
27
  from synapse.logging.context import (
28
28
  ContextResourceUsage,
29
29
  LoggingContext,
30
+ PreserveLoggingContext,
30
31
  nested_logging_context,
31
- set_current_context,
32
32
  )
33
33
  from synapse.metrics import SERVER_NAME_LABEL, LaterGauge
34
34
  from synapse.metrics.background_process_metrics import (
35
- run_as_background_process,
36
35
  wrap_as_background_process,
37
36
  )
38
37
  from synapse.types import JsonMapping, ScheduledTask, TaskStatus
@@ -107,10 +106,8 @@ class TaskScheduler:
107
106
  OCCASIONAL_REPORT_INTERVAL_MS = 5 * 60 * 1000 # 5 minutes
108
107
 
109
108
  def __init__(self, hs: "HomeServer"):
110
- self._hs = hs
111
- self.server_name = (
112
- hs.hostname
113
- ) # nb must be called this for @wrap_as_background_process
109
+ self.hs = hs # nb must be called this for @wrap_as_background_process
110
+ self.server_name = hs.hostname
114
111
  self._store = hs.get_datastores().main
115
112
  self._clock = hs.get_clock()
116
113
  self._running_tasks: Set[str] = set()
@@ -215,7 +212,7 @@ class TaskScheduler:
215
212
  if self._run_background_tasks:
216
213
  self._launch_scheduled_tasks()
217
214
  else:
218
- self._hs.get_replication_command_handler().send_new_active_task(task.id)
215
+ self.hs.get_replication_command_handler().send_new_active_task(task.id)
219
216
 
220
217
  return task.id
221
218
 
@@ -362,7 +359,7 @@ class TaskScheduler:
362
359
  finally:
363
360
  self._launching_new_tasks = False
364
361
 
365
- run_as_background_process("launch_scheduled_tasks", self.server_name, inner)
362
+ self.hs.run_as_background_process("launch_scheduled_tasks", inner)
366
363
 
367
364
  @wrap_as_background_process("clean_scheduled_tasks")
368
365
  async def _clean_scheduled_tasks(self) -> None:
@@ -425,14 +422,11 @@ class TaskScheduler:
425
422
  """
426
423
 
427
424
  current_time = self._clock.time()
428
- calling_context = set_current_context(task_log_context)
429
- try:
425
+ with PreserveLoggingContext(task_log_context):
430
426
  usage = task_log_context.get_resource_usage()
431
427
  TaskScheduler._log_task_usage(
432
428
  "continuing", task, usage, current_time - start_time
433
429
  )
434
- finally:
435
- set_current_context(calling_context)
436
430
 
437
431
  async def wrapper() -> None:
438
432
  with nested_logging_context(task.id) as log_context:
@@ -473,7 +467,10 @@ class TaskScheduler:
473
467
  occasional_status_call.stop()
474
468
 
475
469
  # Try launch a new task since we've finished with this one.
476
- self._clock.call_later(0.1, self._launch_scheduled_tasks)
470
+ self._clock.call_later(
471
+ 0.1,
472
+ self._launch_scheduled_tasks,
473
+ )
477
474
 
478
475
  if len(self._running_tasks) >= TaskScheduler.MAX_CONCURRENT_RUNNING_TASKS:
479
476
  return
@@ -493,4 +490,4 @@ class TaskScheduler:
493
490
 
494
491
  self._running_tasks.add(task.id)
495
492
  await self.update_task(task.id, status=TaskStatus.ACTIVE)
496
- run_as_background_process(f"task-{task.action}", self.server_name, wrapper)
493
+ self.hs.run_as_background_process(f"task-{task.action}", wrapper)
synapse/logging/filter.py DELETED
@@ -1,38 +0,0 @@
1
- #
2
- # This file is licensed under the Affero General Public License (AGPL) version 3.
3
- #
4
- # Copyright 2020 The Matrix.org Foundation C.I.C.
5
- # Copyright (C) 2023 New Vector, Ltd
6
- #
7
- # This program is free software: you can redistribute it and/or modify
8
- # it under the terms of the GNU Affero General Public License as
9
- # published by the Free Software Foundation, either version 3 of the
10
- # License, or (at your option) any later version.
11
- #
12
- # See the GNU Affero General Public License for more details:
13
- # <https://www.gnu.org/licenses/agpl-3.0.html>.
14
- #
15
- # Originally licensed under the Apache License, Version 2.0:
16
- # <http://www.apache.org/licenses/LICENSE-2.0>.
17
- #
18
- # [This file includes modifications made by New Vector Limited]
19
- #
20
- #
21
- import logging
22
- from typing import Literal
23
-
24
-
25
- class MetadataFilter(logging.Filter):
26
- """Logging filter that adds constant values to each record.
27
-
28
- Args:
29
- metadata: Key-value pairs to add to each record.
30
- """
31
-
32
- def __init__(self, metadata: dict):
33
- self._metadata = metadata
34
-
35
- def filter(self, record: logging.LogRecord) -> Literal[True]:
36
- for key, value in self._metadata.items():
37
- setattr(record, key, value)
38
- return True