Skip to content

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

⚠️ Parser warning

The parser emitted a warning. Please review your JUnit XML file:
Warning while parsing testcase attributes: Limit of string is 1000 chars, for name, we got 2301 at 1:2550 in /__w/sentry-python/sentry-python/.junitxml

For more help, visit our troubleshooting guide.

@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?

if not self._should_join_thread():
return
if self._thread: # typing
self._thread.join()
Copy link
Member

Choose a reason for hiding this comment

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

sorry but I actually don't understand this change at all properly

the flush function is called by the thread in the loop, so joining that thread from within flush makes no sense, it should be done from the calling thread?

Copy link
Member

@untitaker untitaker Jul 10, 2025

Choose a reason for hiding this comment

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

yeah this might deadlock if flush is called from within the thread. the goal was to make it so that client.close() blocks until the thread is actually gone. client also calls flush directly, and in that call, blocking here makes sense.

proposal: let's block in kill() until the thread is gone, or make flush take a kwarg like flush(join_thread=True)

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.

4 participants