Fix up logcontexts

This commit is contained in:
Erik Johnston 2016-02-04 10:22:44 +00:00
parent 13e6262659
commit 2c1fbea531
31 changed files with 356 additions and 229 deletions

View file

@ -19,7 +19,7 @@ from twisted.internet import defer, reactor
from synapse.events import FrozenEvent, USE_FROZEN_DICTS
from synapse.events.utils import prune_event
from synapse.util.logcontext import preserve_context_over_deferred
from synapse.util.logcontext import preserve_fn, PreserveLoggingContext
from synapse.util.logutils import log_function
from synapse.api.constants import EventTypes
@ -664,14 +664,16 @@ class EventsStore(SQLBaseStore):
for ids, d in lst:
if not d.called:
try:
d.callback([
res[i]
for i in ids
if i in res
])
with PreserveLoggingContext():
d.callback([
res[i]
for i in ids
if i in res
])
except:
logger.exception("Failed to callback")
reactor.callFromThread(fire, event_list, row_dict)
with PreserveLoggingContext():
reactor.callFromThread(fire, event_list, row_dict)
except Exception as e:
logger.exception("do_fetch")
@ -679,10 +681,12 @@ class EventsStore(SQLBaseStore):
def fire(evs):
for _, d in evs:
if not d.called:
d.errback(e)
with PreserveLoggingContext():
d.errback(e)
if event_list:
reactor.callFromThread(fire, event_list)
with PreserveLoggingContext():
reactor.callFromThread(fire, event_list)
@defer.inlineCallbacks
def _enqueue_events(self, events, check_redacted=True,
@ -709,18 +713,20 @@ class EventsStore(SQLBaseStore):
should_start = False
if should_start:
self.runWithConnection(
self._do_fetch
)
with PreserveLoggingContext():
self.runWithConnection(
self._do_fetch
)
rows = yield preserve_context_over_deferred(events_d)
with PreserveLoggingContext():
rows = yield events_d
if not allow_rejected:
rows[:] = [r for r in rows if not r["rejects"]]
res = yield defer.gatherResults(
[
self._get_event_from_row(
preserve_fn(self._get_event_from_row)(
row["internal_metadata"], row["json"], row["redacts"],
check_redacted=check_redacted,
get_prev_content=get_prev_content,