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

Fix a number of "Starting txn from sentinel context" warnings #5605

Merged
merged 1 commit into from
Jul 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/5605.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a number of "Starting txn from sentinel context" warnings.
10 changes: 9 additions & 1 deletion synapse/handlers/account_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from twisted.internet import defer

from synapse.api.errors import StoreError
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.types import UserID
from synapse.util import stringutils
from synapse.util.logcontext import make_deferred_yieldable
Expand Down Expand Up @@ -67,7 +68,14 @@ def __init__(self, hs):
)

# Check the renewal emails to send and send them every 30min.
self.clock.looping_call(self.send_renewal_emails, 30 * 60 * 1000)
def send_emails():
# run as a background process to make sure that the database transactions
# have a logcontext to report to
return run_as_background_process(
"send_renewals", self.send_renewal_emails
)

self.clock.looping_call(send_emails, 30 * 60 * 1000)

@defer.inlineCallbacks
def send_renewal_emails(self):
Expand Down
9 changes: 8 additions & 1 deletion synapse/storage/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,14 @@ def __init__(self, db_conn, hs):
)

# Read the extrems every 60 minutes
hs.get_clock().looping_call(self._read_forward_extremities, 60 * 60 * 1000)
def read_forward_extremities():
# run as a background process to make sure that the database transactions
# have a logcontext to report to
return run_as_background_process(
"read_forward_extremities", self._read_forward_extremities
)

hs.get_clock().looping_call(read_forward_extremities, 60 * 60 * 1000)

@defer.inlineCallbacks
def _read_forward_extremities(self):
Expand Down
13 changes: 10 additions & 3 deletions synapse/storage/registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from synapse.api.constants import UserTypes
from synapse.api.errors import Codes, StoreError, ThreepidValidationError
from synapse.metrics.background_process_metrics import run_as_background_process
from synapse.storage import background_updates
from synapse.storage._base import SQLBaseStore
from synapse.types import UserID
Expand Down Expand Up @@ -619,9 +620,15 @@ def __init__(self, db_conn, hs):
)

# Create a background job for culling expired 3PID validity tokens
hs.get_clock().looping_call(
self.cull_expired_threepid_validation_tokens, THIRTY_MINUTES_IN_MS
)
def start_cull():
# run as a background process to make sure that the database transactions
# have a logcontext to report to
return run_as_background_process(
"cull_expired_threepid_validation_tokens",
self.cull_expired_threepid_validation_tokens,
)

hs.get_clock().looping_call(start_cull, THIRTY_MINUTES_IN_MS)

@defer.inlineCallbacks
def _backgroud_update_set_deactivated_flag(self, progress, batch_size):
Expand Down
8 changes: 7 additions & 1 deletion synapse/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ def time_msec(self):
def looping_call(self, f, msec):
"""Call a function repeatedly.

Waits `msec` initially before calling `f` for the first time.
Waits `msec` initially before calling `f` for the first time.

Note that the function will be called with no logcontext, so if it is anything
other than trivial, you probably want to wrap it in run_as_background_process.

Args:
f(function): The function to call repeatedly.
Expand All @@ -77,6 +80,9 @@ def looping_call(self, f, msec):
def call_later(self, delay, callback, *args, **kwargs):
"""Call something later

Note that the function will be called with no logcontext, so if it is anything
other than trivial, you probably want to wrap it in run_as_background_process.

Args:
delay(float): How long to wait in seconds.
callback(function): Function to call
Expand Down