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

Commit 91753ca

Browse files
authored
Fix a number of "Starting txn from sentinel context" warnings (#5605)
Fixes #5602, #5603
1 parent c7b48bd commit 91753ca

File tree

5 files changed

+35
-6
lines changed

5 files changed

+35
-6
lines changed

changelog.d/5605.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a number of "Starting txn from sentinel context" warnings.

synapse/handlers/account_validity.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from twisted.internet import defer
2323

2424
from synapse.api.errors import StoreError
25+
from synapse.metrics.background_process_metrics import run_as_background_process
2526
from synapse.types import UserID
2627
from synapse.util import stringutils
2728
from synapse.util.logcontext import make_deferred_yieldable
@@ -67,7 +68,14 @@ def __init__(self, hs):
6768
)
6869

6970
# Check the renewal emails to send and send them every 30min.
70-
self.clock.looping_call(self.send_renewal_emails, 30 * 60 * 1000)
71+
def send_emails():
72+
# run as a background process to make sure that the database transactions
73+
# have a logcontext to report to
74+
return run_as_background_process(
75+
"send_renewals", self.send_renewal_emails
76+
)
77+
78+
self.clock.looping_call(send_emails, 30 * 60 * 1000)
7179

7280
@defer.inlineCallbacks
7381
def send_renewal_emails(self):

synapse/storage/events.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,14 @@ def __init__(self, db_conn, hs):
253253
)
254254

255255
# Read the extrems every 60 minutes
256-
hs.get_clock().looping_call(self._read_forward_extremities, 60 * 60 * 1000)
256+
def read_forward_extremities():
257+
# run as a background process to make sure that the database transactions
258+
# have a logcontext to report to
259+
return run_as_background_process(
260+
"read_forward_extremities", self._read_forward_extremities
261+
)
262+
263+
hs.get_clock().looping_call(read_forward_extremities, 60 * 60 * 1000)
257264

258265
@defer.inlineCallbacks
259266
def _read_forward_extremities(self):

synapse/storage/registration.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
from synapse.api.constants import UserTypes
2727
from synapse.api.errors import Codes, StoreError, ThreepidValidationError
28+
from synapse.metrics.background_process_metrics import run_as_background_process
2829
from synapse.storage import background_updates
2930
from synapse.storage._base import SQLBaseStore
3031
from synapse.types import UserID
@@ -619,9 +620,15 @@ def __init__(self, db_conn, hs):
619620
)
620621

621622
# Create a background job for culling expired 3PID validity tokens
622-
hs.get_clock().looping_call(
623-
self.cull_expired_threepid_validation_tokens, THIRTY_MINUTES_IN_MS
624-
)
623+
def start_cull():
624+
# run as a background process to make sure that the database transactions
625+
# have a logcontext to report to
626+
return run_as_background_process(
627+
"cull_expired_threepid_validation_tokens",
628+
self.cull_expired_threepid_validation_tokens,
629+
)
630+
631+
hs.get_clock().looping_call(start_cull, THIRTY_MINUTES_IN_MS)
625632

626633
@defer.inlineCallbacks
627634
def _backgroud_update_set_deactivated_flag(self, progress, batch_size):

synapse/util/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def time_msec(self):
6262
def looping_call(self, f, msec):
6363
"""Call a function repeatedly.
6464
65-
Waits `msec` initially before calling `f` for the first time.
65+
Waits `msec` initially before calling `f` for the first time.
66+
67+
Note that the function will be called with no logcontext, so if it is anything
68+
other than trivial, you probably want to wrap it in run_as_background_process.
6669
6770
Args:
6871
f(function): The function to call repeatedly.
@@ -77,6 +80,9 @@ def looping_call(self, f, msec):
7780
def call_later(self, delay, callback, *args, **kwargs):
7881
"""Call something later
7982
83+
Note that the function will be called with no logcontext, so if it is anything
84+
other than trivial, you probably want to wrap it in run_as_background_process.
85+
8086
Args:
8187
delay(float): How long to wait in seconds.
8288
callback(function): Function to call

0 commit comments

Comments
 (0)