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

Commit c144252

Browse files
authored
Merge pull request #3710 from matrix-org/rav/logcontext_for_pusher_updates
Fix logcontexts for running pushers
2 parents c334ca6 + 4c9da14 commit c144252

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

changelog.d/3710.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix "Starting db txn 'get_all_updated_receipts' from sentinel context" warning

synapse/app/pusher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,11 @@ def poke_pushers(self, stream_name, token, rows):
162162
else:
163163
yield self.start_pusher(row.user_id, row.app_id, row.pushkey)
164164
elif stream_name == "events":
165-
yield self.pusher_pool.on_new_notifications(
165+
self.pusher_pool.on_new_notifications(
166166
token, token,
167167
)
168168
elif stream_name == "receipts":
169-
yield self.pusher_pool.on_new_receipts(
169+
self.pusher_pool.on_new_receipts(
170170
token, token, set(row.room_id for row in rows)
171171
)
172172
except Exception:

synapse/handlers/federation.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2386,8 +2386,7 @@ def _notify_persisted_event(self, event, max_stream_id):
23862386
extra_users=extra_users
23872387
)
23882388

2389-
logcontext.run_in_background(
2390-
self.pusher_pool.on_new_notifications,
2389+
self.pusher_pool.on_new_notifications(
23912390
event_stream_id, max_stream_id,
23922391
)
23932392

synapse/handlers/message.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -778,11 +778,8 @@ def is_inviter_member_event(e):
778778
event, context=context
779779
)
780780

781-
# this intentionally does not yield: we don't care about the result
782-
# and don't need to wait for it.
783-
run_in_background(
784-
self.pusher_pool.on_new_notifications,
785-
event_stream_id, max_stream_id
781+
self.pusher_pool.on_new_notifications(
782+
event_stream_id, max_stream_id,
786783
)
787784

788785
def _notify():

synapse/handlers/receipts.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
from synapse.types import get_domain_from_id
2020
from synapse.util import logcontext
21-
from synapse.util.logcontext import PreserveLoggingContext
2221

2322
from ._base import BaseHandler
2423

@@ -116,16 +115,15 @@ def _handle_new_receipts(self, receipts):
116115

117116
affected_room_ids = list(set([r["room_id"] for r in receipts]))
118117

119-
with PreserveLoggingContext():
120-
self.notifier.on_new_event(
121-
"receipt_key", max_batch_id, rooms=affected_room_ids
122-
)
123-
# Note that the min here shouldn't be relied upon to be accurate.
124-
self.hs.get_pusherpool().on_new_receipts(
125-
min_batch_id, max_batch_id, affected_room_ids
126-
)
118+
self.notifier.on_new_event(
119+
"receipt_key", max_batch_id, rooms=affected_room_ids
120+
)
121+
# Note that the min here shouldn't be relied upon to be accurate.
122+
self.hs.get_pusherpool().on_new_receipts(
123+
min_batch_id, max_batch_id, affected_room_ids,
124+
)
127125

128-
defer.returnValue(True)
126+
defer.returnValue(True)
129127

130128
@logcontext.preserve_fn # caller should not yield on this
131129
@defer.inlineCallbacks

synapse/push/pusherpool.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
from twisted.internet import defer
2020

21+
from synapse.metrics.background_process_metrics import run_as_background_process
2122
from synapse.push.pusher import PusherFactory
2223
from synapse.util.logcontext import make_deferred_yieldable, run_in_background
2324

@@ -122,8 +123,14 @@ def remove_pushers_by_access_token(self, user_id, access_tokens):
122123
p['app_id'], p['pushkey'], p['user_name'],
123124
)
124125

125-
@defer.inlineCallbacks
126126
def on_new_notifications(self, min_stream_id, max_stream_id):
127+
run_as_background_process(
128+
"on_new_notifications",
129+
self._on_new_notifications, min_stream_id, max_stream_id,
130+
)
131+
132+
@defer.inlineCallbacks
133+
def _on_new_notifications(self, min_stream_id, max_stream_id):
127134
try:
128135
users_affected = yield self.store.get_push_action_users_in_range(
129136
min_stream_id, max_stream_id
@@ -147,8 +154,14 @@ def on_new_notifications(self, min_stream_id, max_stream_id):
147154
except Exception:
148155
logger.exception("Exception in pusher on_new_notifications")
149156

150-
@defer.inlineCallbacks
151157
def on_new_receipts(self, min_stream_id, max_stream_id, affected_room_ids):
158+
run_as_background_process(
159+
"on_new_receipts",
160+
self._on_new_receipts, min_stream_id, max_stream_id, affected_room_ids,
161+
)
162+
163+
@defer.inlineCallbacks
164+
def _on_new_receipts(self, min_stream_id, max_stream_id, affected_room_ids):
152165
try:
153166
# Need to subtract 1 from the minimum because the lower bound here
154167
# is not inclusive

0 commit comments

Comments
 (0)