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

Avoid reraise, to improve stacktraces #3989

Merged
merged 1 commit into from
Oct 2, 2018
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/3989.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve stacktraces in certain exceptions in the logs
20 changes: 10 additions & 10 deletions synapse/handlers/federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import itertools
import logging
import sys

import six
from six import iteritems, itervalues
Expand Down Expand Up @@ -1602,6 +1601,9 @@ def _handle_new_event(self, origin, event, state=None, auth_events=None,
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:
if not event.internal_metadata.is_outlier() and not backfilled:
yield self.action_generator.handle_push_actions_for_event(
Expand All @@ -1612,15 +1614,13 @@ def _handle_new_event(self, origin, event, state=None, auth_events=None,
[(event, context)],
backfilled=backfilled,
)
except: # noqa: E722, as we reraise the exception this is fine.
tp, value, tb = sys.exc_info()

logcontext.run_in_background(
self.store.remove_push_actions_from_staging,
event.event_id,
)

six.reraise(tp, value, tb)
success = True
finally:
if not success:
logcontext.run_in_background(
self.store.remove_push_actions_from_staging,
event.event_id,
)

defer.returnValue(context)

Expand Down
25 changes: 13 additions & 12 deletions synapse/handlers/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import logging
import sys

import six
from six import iteritems, itervalues, string_types

from canonicaljson import encode_canonical_json, json
Expand Down Expand Up @@ -624,6 +622,9 @@ def handle_new_client_event(
event, context
)

# reraise does not allow inlineCallbacks to preserve the stacktrace, so we
# hack around with a try/finally instead.
success = False
try:
# If we're a worker we need to hit out to the master.
if self.config.worker_app:
Expand All @@ -636,6 +637,7 @@ def handle_new_client_event(
ratelimit=ratelimit,
extra_users=extra_users,
)
success = True
return

yield self.persist_and_notify_client_event(
Expand All @@ -645,17 +647,16 @@ def handle_new_client_event(
ratelimit=ratelimit,
extra_users=extra_users,
)
except: # noqa: E722, as we reraise the exception this is fine.
# Ensure that we actually remove the entries in the push actions
# staging area, if we calculated them.
tp, value, tb = sys.exc_info()

run_in_background(
self.store.remove_push_actions_from_staging,
event.event_id,
)

six.reraise(tp, value, tb)
success = True
finally:
if not success:
# Ensure that we actually remove the entries in the push actions
# staging area, if we calculated them.
run_in_background(
self.store.remove_push_actions_from_staging,
event.event_id,
)

@defer.inlineCallbacks
def persist_and_notify_client_event(
Expand Down