René's URL Explorer Experiment


Title: `flush()` can return before a batch taken by the flusher thread reaches the transport · Issue #8300 · getsentry/sentry-python · GitHub

Open Graph Title: `flush()` can return before a batch taken by the flusher thread reaches the transport · Issue #8300 · getsentry/sentry-python

X Title: `flush()` can return before a batch taken by the flusher thread reaches the transport · Issue #8300 · getsentry/sentry-python

Description: How do you use Sentry? Self-hosted/on-premise Version 2.75.0 (Python 3.15.2, only sentry-sdk installed); also reproduces on 2.72.0, and master at e9c62e5 has the same code Steps to Reproduce Client.flush() can return before a batch is de...

Open Graph Description: How do you use Sentry? Self-hosted/on-premise Version 2.75.0 (Python 3.15.2, only sentry-sdk installed); also reproduces on 2.72.0, and master at e9c62e5 has the same code Steps to Reproduce Client...

X Description: How do you use Sentry? Self-hosted/on-premise Version 2.75.0 (Python 3.15.2, only sentry-sdk installed); also reproduces on 2.72.0, and master at e9c62e5 has the same code Steps to Reproduce Client...

Opengraph URL: https://github.com/getsentry/sentry-python/issues/8300

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`flush()` can return before a batch taken by the flusher thread reaches the transport","articleBody":"### How do you use Sentry?\n\nSelf-hosted/on-premise\n\n### Version\n\n2.75.0 (Python 3.15.2, only `sentry-sdk` installed); also reproduces on 2.72.0, and `master` at e9c62e53 has the same code\n\n### Steps to Reproduce\n\n`Client.flush()` can return before a batch is delivered to the transport. The batcher's flusher thread removes the batch from the buffer under `_lock` and calls `_capture_func` only after releasing it (`Batcher._flush`, `SpanBatcher._flush`). A `flush()` from another thread that runs in this window finds the buffer empty and returns at once, while the batch is still on its way to the transport.\n\nThe same window applies to logs and metrics (`Batcher._flush`) and to streamed spans (`SpanBatcher._flush`). For spans it opens right after a segment ends, since the segment end wakes the flusher thread immediately.\n\nThe transport below only widens the window so the race reproduces every time:\n\n```python\nimport threading\nimport time\n\nimport sentry_sdk\nfrom sentry_sdk.transport import Transport\n\nreceived = []\ntaken = threading.Event()\n\n\nclass SlowTransport(Transport):\n    def capture_envelope(self, envelope):\n        if threading.current_thread() is not threading.main_thread():\n            taken.set()\n            time.sleep(0.5)  # widen the window: batch already removed from the buffer\n        received.extend(item.type for item in envelope.items)\n\n\nsentry_sdk.init(\n    dsn=\"https://public@example.invalid/1\",\n    transport=SlowTransport,\n    trace_lifecycle=\"stream\",\n    traces_sample_rate=1.0,\n)\n\nwith sentry_sdk.traces.start_span(name=\"segment\"):\n    pass\n\ntaken.wait()  # the flusher thread has taken the batch and is delivering it\nsentry_sdk.flush()\nprint(\"after flush():\", received)\n```\n\n### Expected Result\n\n`after flush(): ['span']` — `flush()` is documented as \"Wait for the current events to be sent\".\n\n### Actual Result\n\n`after flush(): []`; the span arrives later.\n\nTwo consequences:\n- Tests that capture envelopes with an in-memory transport and assert after `flush()` are flaky.\n- `Client.close()` calls `flush()` and then sets `self.transport = None`. A batch in the window then reaches `_capture_envelope` with no transport and is dropped silently, so the last spans or logs of a shutting-down process can be lost.\n\nThe SDK's own test suite already works around this: `_install_flush_completion_handshake` in `tests/conftest.py`, added in #7170, makes `flush()` wait for the flusher thread, and #7170 describes the race. User code and user test suites have no such hook without patching private batcher internals.\n\nA possible fix: a separate flush lock held for the whole `_flush`, including the `_capture_func` call. `_lock` stays short, so it doesn't interfere with the deadlock fix in #5684, the open PR #7776, or the change proposed in #8023. A `flush()` from the user's thread then waits for an in-flight flush of the flusher thread before draining the rest. On its own this lock isn't enough, though: a reentrant `flush()` from a transport would deadlock on it (see the comments below).\n\n","author":{"url":"https://github.com/Flamefork","@type":"Person","name":"Flamefork"},"datePublished":"2026-11-16T14:40:36Z","url":"https://github.com/getsentry/sentry-python/issues/8300"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:cc2ec12a-5d53-ed0e-f912-2dbcb4890708
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE804:172B92:874A4E:B6B29B:6B00E2FF
html-safe-nonceb3823f8c5d80b84c31c0f30ffa5a9163aa1ccd90ce8c65cbbf2ec4c03bde50b3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFODA0OjE3MkI5Mjo4NzRBNEU6QjZCMjlCOjZCMDBFMkZGIiwidmlzaXRvcl9pZCI6IjgzNTY3NTg4MjY0MzA1NTQ4NzkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac807e5a07078fc90c8a98510a74b4110ce45ae1d6afa0b79879f3e8a2fc3633f6
hovercard-subject-tagissue:6423653777
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/8300/issue_layout
twitter:imagehttps://opengraph.githubassets.com/122c63a08ac8716ee5faa378c283063ec1e22df6448f6c426bd2876a06b5d45d/getsentry/sentry-python/issues/8300
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/122c63a08ac8716ee5faa378c283063ec1e22df6448f6c426bd2876a06b5d45d/getsentry/sentry-python/issues/8300
og:image:altHow do you use Sentry? Self-hosted/on-premise Version 2.75.0 (Python 3.15.2, only sentry-sdk installed); also reproduces on 2.72.0, and master at e9c62e5 has the same code Steps to Reproduce Client...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameFlamefork
hostnamegithub.com
expected-hostnamegithub.com
None27088b6977484d0d3321d9a11c907c6d6637b315cfa359ef7952dbf6292f9b14
turbo-cache-controlno-preview
go-importgithub.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git
octolytics-dimension-user_id1396951
octolytics-dimension-user_logingetsentry
octolytics-dimension-repository_id137814779
octolytics-dimension-repository_nwogetsentry/sentry-python
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id137814779
octolytics-dimension-repository_network_root_nwogetsentry/sentry-python
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624179fb8b88d26ba5bba08894eb60a1c5a1d93d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/getsentry/sentry-python/issues/8300#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-python%2Fissues%2F8300
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgetsentry%2Fsentry-python%2Fissues%2F8300
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=getsentry%2Fsentry-python
Reloadhttps://github.com/getsentry/sentry-python/issues/8300
Reloadhttps://github.com/getsentry/sentry-python/issues/8300
Reloadhttps://github.com/getsentry/sentry-python/issues/8300
getsentryhttps://github.com/getsentry
sentry-pythonhttps://github.com/getsentry/sentry-python
Codehttps://github.com/getsentry/sentry-python
Issues345 (345)https://github.com/getsentry/sentry-python/issues
Pull requests42 (42)https://github.com/getsentry/sentry-python/pulls
Discussionshttps://github.com/getsentry/sentry-python/discussions
Actionshttps://github.com/getsentry/sentry-python/actions
Security and quality2 (2)https://github.com/getsentry/sentry-python/security
Insightshttps://github.com/getsentry/sentry-python/insights
https://github.com/getsentry/sentry-python
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/8300
New issuehttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/8300
#8340https://github.com/getsentry/sentry-python/pull/8340
flush() can return before a batch taken by the flusher thread reaches the transporthttps://github.com/getsentry/sentry-python/issues/8300#top
#8340https://github.com/getsentry/sentry-python/pull/8340
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
PythonSDKhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Python%22
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
https://github.com/Flamefork
Flameforkhttps://github.com/Flamefork
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#issue-6423653777
e9c62e5https://github.com/getsentry/sentry-python/commit/e9c62e532e9a7fcd5702583908ff600bdc02480e
#7170https://github.com/getsentry/sentry-python/pull/7170
#7170https://github.com/getsentry/sentry-python/pull/7170
#5684https://github.com/getsentry/sentry-python/pull/5684
#7776https://github.com/getsentry/sentry-python/pull/7776
#8023https://github.com/getsentry/sentry-python/issues/8023
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#event-36288475697
https://github.com/apps/linear-code
linear-codehttps://github.com/apps/linear-code
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#issuecomment-6919551971
Linear Codehttps://linear.app
PY-3082https://linear.app/getsentry/issue/PY-3082
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#event-36288481901
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300
linear-codehttps://github.com/apps/linear-code
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
PythonSDKhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Python%22
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#event-36288524880
https://github.com/alexander-alderman-webb
alexander-alderman-webbhttps://github.com/alexander-alderman-webb
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#issuecomment-6919714997
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300#event-36289152450
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Nov 16, 2026https://github.com/getsentry/sentry-python/issues/8300
https://github.com/realicon23
realicon23https://github.com/realicon23
on Nov 17, 2026https://github.com/getsentry/sentry-python/issues/8300#issuecomment-6945698813
getsantryhttps://github.com/apps/getsantry
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
on Nov 17, 2026https://github.com/getsentry/sentry-python/issues/8300#event-36393495974
getsantryhttps://github.com/apps/getsantry
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
on Nov 17, 2026https://github.com/getsentry/sentry-python/issues/8300
https://github.com/Flamefork
Flameforkhttps://github.com/Flamefork
on Nov 17, 2026https://github.com/getsentry/sentry-python/issues/8300#issuecomment-6945911529
#7170https://github.com/getsentry/sentry-python/pull/7170
https://github.com/tony1233200
tony1233200https://github.com/tony1233200
on Nov 20, 2026https://github.com/getsentry/sentry-python/issues/8300#issuecomment-7033339105
@Flameforkhttps://github.com/Flamefork
Sign up for freehttps://github.com/signup?return_to=https://github.com/getsentry/sentry-python/issues/8300
Sign in to commenthttps://github.com/login?return_to=https://github.com/getsentry/sentry-python/issues/8300
Bughttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Bug%22
PythonSDKhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Python%22
Waiting for: Product Ownerhttps://github.com/getsentry/sentry-python/issues?q=state%3Aopen%20label%3A%22Waiting%20for%3A%20Product%20Owner%22
GitHub Issues with 👀 3https://github.com/orgs/getsentry/projects/227
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.