Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't fail to finalize observers if one fails #811

Merged
merged 1 commit into from
Oct 25, 2023
Merged

Conversation

bradengroom
Copy link
Member

@bradengroom bradengroom commented Oct 24, 2023

💸 TL;DR

When a request finishes, baseplate invokes on_finish for each observer. Sometimes these finalizers will fail and raise an exception. This causes the loop to exit early and we fail to finalize observers later in the loop. This could result in a few things including postgres sessions not getting closed timely. Raising from a finalizer also means we fail to clean up reference cycles later in the function and leave more work for GC to pick up later.

📜 Details

N/A

🧪 Testing Steps / Validation

✅ Checks

  • CI tests (if present) are passing
  • Adheres to code style for repo
  • Contributor License Agreement (CLA) completed if not a Reddit employee

@bradengroom bradengroom requested a review from a team as a code owner October 24, 2023 16:43
@bradengroom bradengroom changed the title Don't fail to finalize observers is one fails Don't fail to finalize observers if one fails Oct 24, 2023
Copy link
Contributor

@salomon-smekecohen salomon-smekecohen left a comment

Choose a reason for hiding this comment

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

Thank you B money.

@spladug
Copy link
Contributor

spladug commented Oct 24, 2023

🐟 good call!

@rram
Copy link
Contributor

rram commented Oct 24, 2023

🐟 lgtm

try:
observer.on_finish(exc_info)
except Exception:
logger.exception("Exception raised while finalizing observer")
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make it so this exception includes all the details the original exception would include. I don't want things to become harder to debug because we're catching this exception.

Copy link
Member Author

Choose a reason for hiding this comment

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

logger.exception actually adds that information for us
https://docs.python.org/3/library/logging.html#logging.Logger.exception

@bradengroom bradengroom merged commit 8c44633 into develop Oct 25, 2023
3 checks passed
@bradengroom bradengroom deleted the on-finish branch October 25, 2023 16:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

5 participants