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

user_directory.notify_new_event throws exception whenever interacting with application service sender #11025

Closed
@MadLittleMods

Description

@MadLittleMods

Found while running the MSC2716 Complement test suite (COMPLEMENT_ALWAYS_PRINT_SERVER_LOGS=1 COMPLEMENT_DIR=../complement ./scripts-dev/complement.sh TestBackfillingHistory).


It looks like the @the-bridge-user:hs1 user (the main appservice sender defined in the appservice registration sender_localpart), which doesn't have an entry in the users database table, is being notified of events when it should be being skipped.

Since this is in a background process, it doesn't stop anything but it's a bunch of noise in the logs.

2021-10-07 16:59:56,530 - synapse.metrics.background_process_metrics - 215 - ERROR - user_directory.notify_new_event-1147 - Background process 'user_directory.notify_new_event' threw an exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/synapse/metrics/background_process_metrics.py", line 213, in run
    return await maybe_awaitable(func(*args, **kwargs))
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/user_directory.py", line 119, in process
    await self._unsafe_process()
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/user_directory.py", line 170, in _unsafe_process
    await self._handle_deltas(deltas)
  File "/usr/local/lib/python3.8/site-packages/synapse/handlers/user_directory.py", line 229, in _handle_deltas
    ) or await self.store.should_include_local_user_in_dir(state_key)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/user_directory.py", line 389, in should_include_local_user_in_dir
    if await self.get_user_deactivated_status(user):
  File "/usr/local/lib/python3.8/site-packages/twisted/internet/defer.py", line 1657, in _inlineCallbacks
    result = current_context.run(
  File "/usr/local/lib/python3.8/site-packages/twisted/python/failure.py", line 500, in throwExceptionIntoGenerator
    return g.throw(self.type, self.value, self.tb)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/databases/main/registration.py", line 929, in get_user_deactivated_status
    res = await self.db_pool.simple_select_one_onecol(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 1414, in simple_select_one_onecol
    return await self.runInteraction(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 686, in runInteraction
    result = await self.runWithConnection(
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 791, in runWithConnection
    return await make_deferred_yieldable(
  File "/usr/local/lib/python3.8/site-packages/twisted/python/threadpool.py", line 238, in inContext
    result = inContext.theWork()  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.8/site-packages/twisted/python/threadpool.py", line 254, in <lambda>
    inContext.theWork = lambda: context.call(  # type: ignore[attr-defined]
  File "/usr/local/lib/python3.8/site-packages/twisted/python/context.py", line 118, in callWithContext
    return self.currentContext().callWithContext(ctx, func, *args, **kw)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/context.py", line 83, in callWithContext
    return func(*args, **kw)
  File "/usr/local/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 293, in _runWithConnection
    compat.reraise(excValue, excTraceback)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/deprecate.py", line 298, in deprecatedFunction
    return function(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/twisted/python/compat.py", line 404, in reraise
    raise exception.with_traceback(traceback)
  File "/usr/local/lib/python3.8/site-packages/twisted/enterprise/adbapi.py", line 284, in _runWithConnection
    result = func(conn, *args, **kw)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 786, in inner_func
    return func(db_conn, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 554, in new_transaction
    r = func(cursor, *args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/synapse/storage/database.py", line 1467, in simple_select_one_onecol_txn
    raise StoreError(404, "No row found")
synapse.api.errors.StoreError: 404: No row found

Relevant code

It looks like this might have regressed in #10960 (can't reproduce on the commit before this change).

Possible remediation

The checks in should_include_local_user_in_dir should probably return early for the main application service user. I see that it already skips any users that the application service controls (matching the exclusive namespace regex) but that is different from the main application service user/sender.

Metadata

Metadata

Assignees

Labels

A-Application-ServiceRelated to AS supportT-DefectBugs, crashes, hangs, security vulnerabilities, or other reported issues.X-RegressionSomething broke which worked on a previous release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions