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

Always close _all_ ijson coroutines, even if doing so raises Exceptions #14065

Merged
merged 5 commits into from
Oct 6, 2022

Conversation

DMRobertson
Copy link
Contributor

@DMRobertson DMRobertson commented Oct 5, 2022

Fixes #13293. Improves on #12875 and #9958.

This change means that we should raise one Sentry event for each such failure to .finish() a parser, instead of an event for each line printed to stderr.

I have only included the first traceback exceptions[0]: I'm assuming that's enough to diagnose what happened if we see this error. I do make sure to include the str() of each individual exception though.

I considered using https://pypi.org/project/exceptiongroup/ but this was a little scary: it mentions patching TracebackException and adding exception hooks; I feared that this wouldn't play nicely with twisted + logcontexts + other arcanery in Synapse I don't grok.

@DMRobertson DMRobertson changed the title Introduce an ExceptionBundle Always close _all_ ijson coroutines, even if doing so raises Exceptions Oct 5, 2022
@DMRobertson DMRobertson marked this pull request as ready for review October 5, 2022 16:49
@DMRobertson DMRobertson requested a review from a team as a code owner October 5, 2022 16:49
@squahtx
Copy link
Contributor

squahtx commented Oct 5, 2022

Thanks for picking this up!

Comment on lines +994 to +996
raise ExceptionBundle(
f"There were {len(exceptions)} errors closing coroutines", exceptions
) from exceptions[0]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not promising this is the cleanest way to do it---there are no tracebacks for exceptions[1:]---but this seemed Good Enough.

Copy link
Contributor Author

@DMRobertson DMRobertson Oct 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'm not sure what @richvdh meant by exception chanining in #13293 (comment) ---something along these lines?)

Comment on lines +205 to +206
parts.append(str(e))
super().__init__("\n - ".join(parts))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm specifically trying to ensure each exception's summary is included here, even if we don't have their tracebacks.

There are some comments in the description elaborating on why I didn't want to use the backport here,

Copy link
Contributor

@reivilibre reivilibre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems good to me, thanks!

tests/federation/transport/test_client.py Show resolved Hide resolved
@DMRobertson DMRobertson enabled auto-merge (squash) October 6, 2022 17:48
@DMRobertson DMRobertson merged commit cb20b88 into develop Oct 6, 2022
@DMRobertson DMRobertson deleted the dmr/ijson-coroutines branch October 6, 2022 18:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Close ijson coroutines ourselves instead of letting the GC close them
3 participants