forked from MirrorHub/synapse
Merge pull request #3989 from matrix-org/rav/better_stacktraces
Avoid reraise, to improve stacktraces
This commit is contained in:
commit
8c41b0ca66
3 changed files with 24 additions and 22 deletions
1
changelog.d/3989.misc
Normal file
1
changelog.d/3989.misc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Improve stacktraces in certain exceptions in the logs
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
import six
|
import six
|
||||||
from six import iteritems, itervalues
|
from six import iteritems, itervalues
|
||||||
|
@ -1602,6 +1601,9 @@ class FederationHandler(BaseHandler):
|
||||||
auth_events=auth_events,
|
auth_events=auth_events,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# reraise does not allow inlineCallbacks to preserve the stacktrace, so we
|
||||||
|
# hack around with a try/finally instead.
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
if not event.internal_metadata.is_outlier() and not backfilled:
|
if not event.internal_metadata.is_outlier() and not backfilled:
|
||||||
yield self.action_generator.handle_push_actions_for_event(
|
yield self.action_generator.handle_push_actions_for_event(
|
||||||
|
@ -1612,16 +1614,14 @@ class FederationHandler(BaseHandler):
|
||||||
[(event, context)],
|
[(event, context)],
|
||||||
backfilled=backfilled,
|
backfilled=backfilled,
|
||||||
)
|
)
|
||||||
except: # noqa: E722, as we reraise the exception this is fine.
|
success = True
|
||||||
tp, value, tb = sys.exc_info()
|
finally:
|
||||||
|
if not success:
|
||||||
logcontext.run_in_background(
|
logcontext.run_in_background(
|
||||||
self.store.remove_push_actions_from_staging,
|
self.store.remove_push_actions_from_staging,
|
||||||
event.event_id,
|
event.event_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
six.reraise(tp, value, tb)
|
|
||||||
|
|
||||||
defer.returnValue(context)
|
defer.returnValue(context)
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
|
|
|
@ -14,9 +14,7 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
import logging
|
import logging
|
||||||
import sys
|
|
||||||
|
|
||||||
import six
|
|
||||||
from six import iteritems, itervalues, string_types
|
from six import iteritems, itervalues, string_types
|
||||||
|
|
||||||
from canonicaljson import encode_canonical_json, json
|
from canonicaljson import encode_canonical_json, json
|
||||||
|
@ -624,6 +622,9 @@ class EventCreationHandler(object):
|
||||||
event, context
|
event, context
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# reraise does not allow inlineCallbacks to preserve the stacktrace, so we
|
||||||
|
# hack around with a try/finally instead.
|
||||||
|
success = False
|
||||||
try:
|
try:
|
||||||
# If we're a worker we need to hit out to the master.
|
# If we're a worker we need to hit out to the master.
|
||||||
if self.config.worker_app:
|
if self.config.worker_app:
|
||||||
|
@ -636,6 +637,7 @@ class EventCreationHandler(object):
|
||||||
ratelimit=ratelimit,
|
ratelimit=ratelimit,
|
||||||
extra_users=extra_users,
|
extra_users=extra_users,
|
||||||
)
|
)
|
||||||
|
success = True
|
||||||
return
|
return
|
||||||
|
|
||||||
yield self.persist_and_notify_client_event(
|
yield self.persist_and_notify_client_event(
|
||||||
|
@ -645,18 +647,17 @@ class EventCreationHandler(object):
|
||||||
ratelimit=ratelimit,
|
ratelimit=ratelimit,
|
||||||
extra_users=extra_users,
|
extra_users=extra_users,
|
||||||
)
|
)
|
||||||
except: # noqa: E722, as we reraise the exception this is fine.
|
|
||||||
|
success = True
|
||||||
|
finally:
|
||||||
|
if not success:
|
||||||
# Ensure that we actually remove the entries in the push actions
|
# Ensure that we actually remove the entries in the push actions
|
||||||
# staging area, if we calculated them.
|
# staging area, if we calculated them.
|
||||||
tp, value, tb = sys.exc_info()
|
|
||||||
|
|
||||||
run_in_background(
|
run_in_background(
|
||||||
self.store.remove_push_actions_from_staging,
|
self.store.remove_push_actions_from_staging,
|
||||||
event.event_id,
|
event.event_id,
|
||||||
)
|
)
|
||||||
|
|
||||||
six.reraise(tp, value, tb)
|
|
||||||
|
|
||||||
@defer.inlineCallbacks
|
@defer.inlineCallbacks
|
||||||
def persist_and_notify_client_event(
|
def persist_and_notify_client_event(
|
||||||
self,
|
self,
|
||||||
|
|
Loading…
Reference in a new issue