Skip to content

fix(sessions): clean up threading on kill+flush #4562

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

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

bukzor
Copy link
Contributor

@bukzor bukzor commented Jul 8, 2025

This follows the precedent set in BackgroundWorker.flush, and helps me with my project
to assert thread hygeine in sentry test suite (related: DI-1008), but also makes
the system much more deterministic for everyone.

This will cause shutdown to be quite slow until #4561 goes in. So I'd reject
this if you reject that.

@bukzor bukzor requested a review from untitaker July 8, 2025 22:28
Copy link

codecov bot commented Jul 8, 2025

Codecov Report

Attention: Patch coverage is 42.85714% with 8 lines in your changes missing coverage. Please review.

Project coverage is 80.65%. Comparing base (a7b2d67) to head (cf8a3ed).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
sentry_sdk/sessions.py 42.85% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4562      +/-   ##
==========================================
- Coverage   80.68%   80.65%   -0.03%     
==========================================
  Files         156      156              
  Lines       16482    16494      +12     
  Branches     2802     2805       +3     
==========================================
+ Hits        13299    13304       +5     
- Misses       2299     2306       +7     
  Partials      884      884              
Files with missing lines Coverage Δ
sentry_sdk/sessions.py 75.64% <42.85%> (-3.53%) ⬇️

... and 1 file with indirect coverage changes

@bukzor
Copy link
Contributor Author

bukzor commented Jul 8, 2025

This needs test coverage, apparently. Any hints? I'll do the work.

def _thread_stopping(self):
# type: (...) -> bool
return (
not self._running
Copy link
Member

Choose a reason for hiding this comment

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

there's no more self._running so will wait till you rebase on the other change

bukzor added 2 commits July 9, 2025 12:03
This follows the precedent set in transport.flush, and helps me with my project
to assert thread hygeine in sentry test suite (related: DI-1008), but also makes
the system much more deterministic for everyone.

This will cause shutdown to be quite slow until #4561 goes in. So I'd reject
this if you reject that.
@bukzor bukzor force-pushed the bukzor/can-wait4-session-flusher branch from cf8a3ed to 8d24e88 Compare July 9, 2025 18:18
@@ -190,14 +191,34 @@ def flush(self):
if len(envelope.items) > 0:
self.capture_func(envelope)

# hygiene: deterministically clean up any stopping thread
if not self._should_join_thread():
Copy link
Member

Choose a reason for hiding this comment

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

why are two of these required? isn't the one under the lock sufficient?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants