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

Commit 50e45ab

Browse files
committed
Add debug logging for issue #9553
Hopefully this will help us track down where to-device messages are getting lost/delayed.
1 parent 6c84778 commit 50e45ab

File tree

6 files changed

+41
-1
lines changed

6 files changed

+41
-1
lines changed

changelog.d/9959.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add debug logging for lost/delayed to-device messages.

synapse/federation/sender/per_destination_queue.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from synapse.events import EventBase
2929
from synapse.federation.units import Edu
3030
from synapse.handlers.presence import format_user_presence_state
31+
from synapse.logging import issue9533_logger
3132
from synapse.logging.opentracing import SynapseTags, set_tag
3233
from synapse.metrics import sent_transactions_counter
3334
from synapse.metrics.background_process_metrics import run_as_background_process
@@ -574,6 +575,14 @@ async def _get_to_device_message_edus(self, limit: int) -> Tuple[List[Edu], int]
574575
for content in contents
575576
]
576577

578+
if edus:
579+
issue9533_logger.debug(
580+
"Sending %i to-device messages to %s, up to stream id %i",
581+
len(edus),
582+
self._destination,
583+
stream_id,
584+
)
585+
577586
return (edus, stream_id)
578587

579588
def _start_catching_up(self) -> None:

synapse/logging/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
# limitations under the License.
1414

1515
# These are imported to allow for nicer logging configuration files.
16+
import logging
17+
1618
from synapse.logging._remote import RemoteHandler
1719
from synapse.logging._terse_json import JsonFormatter, TerseJsonFormatter
1820

1921
__all__ = ["RemoteHandler", "JsonFormatter", "TerseJsonFormatter"]
22+
23+
# Debug logger for https://github.com/matrix-org/synapse/issues/9533 etc
24+
issue9533_logger = logging.getLogger("synapse.9533_debug")

synapse/notifier.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from synapse.api.errors import AuthError
3939
from synapse.events import EventBase
4040
from synapse.handlers.presence import format_user_presence_state
41+
from synapse.logging import issue9533_logger
4142
from synapse.logging.context import PreserveLoggingContext
4243
from synapse.logging.opentracing import log_kv, start_active_span
4344
from synapse.logging.utils import log_function
@@ -426,6 +427,13 @@ def on_new_event(
426427
for room in rooms:
427428
user_streams |= self.room_to_user_streams.get(room, set())
428429

430+
if stream_key == "to_device_key":
431+
issue9533_logger.debug(
432+
"to-device messages stream id %s, awaking streams for %s",
433+
new_token,
434+
users,
435+
)
436+
429437
time_now_ms = self.clock.time_msec()
430438
for user_stream in user_streams:
431439
try:

synapse/replication/tcp/client.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151

5252
logger = logging.getLogger(__name__)
5353

54-
5554
# How long we allow callers to wait for replication updates before timing out.
5655
_WAIT_FOR_REPLICATION_TIMEOUT_SECONDS = 30
5756

synapse/storage/databases/main/deviceinbox.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import logging
1616
from typing import List, Optional, Tuple
1717

18+
from synapse.logging import issue9533_logger
1819
from synapse.logging.opentracing import log_kv, set_tag, trace
1920
from synapse.replication.tcp.streams import ToDeviceStream
2021
from synapse.storage._base import SQLBaseStore, db_to_json
@@ -404,6 +405,13 @@ def add_messages_txn(txn, now_ms, stream_id):
404405
],
405406
)
406407

408+
if remote_messages_by_destination:
409+
issue9533_logger.debug(
410+
"Queued outgoing to-device messages with stream_id %i for %s",
411+
stream_id,
412+
list(remote_messages_by_destination.keys()),
413+
)
414+
407415
async with self._device_inbox_id_gen.get_next() as stream_id:
408416
now_ms = self.clock.time_msec()
409417
await self.db_pool.runInteraction(
@@ -533,6 +541,16 @@ def _add_messages_to_local_device_inbox_txn(
533541
],
534542
)
535543

544+
issue9533_logger.debug(
545+
"Stored to-device messages with stream_id %i for %s",
546+
stream_id,
547+
[
548+
(user_id, device_id)
549+
for (user_id, messages_by_device) in local_by_user_then_device.items()
550+
for device_id in messages_by_device.keys()
551+
],
552+
)
553+
536554

537555
class DeviceInboxBackgroundUpdateStore(SQLBaseStore):
538556
DEVICE_INBOX_STREAM_ID = "device_inbox_stream_drop"

0 commit comments

Comments
 (0)