Title: asyncio.CancelledError exceptions are swallowed by capture_internal_exceptions() · Issue #4853 · getsentry/sentry-python · GitHub
Open Graph Title: asyncio.CancelledError exceptions are swallowed by capture_internal_exceptions() · Issue #4853 · getsentry/sentry-python
X Title: asyncio.CancelledError exceptions are swallowed by capture_internal_exceptions() · Issue #4853 · getsentry/sentry-python
Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.38.0 Steps to Reproduce This issue occurs when using OpenAI SDK and Sentry. If you try to cancel a task that is in the middle of processing OpenAI completion iterators, the task wi...
Open Graph Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.38.0 Steps to Reproduce This issue occurs when using OpenAI SDK and Sentry. If you try to cancel a task that is in the middle of processing ...
X Description: How do you use Sentry? Sentry Saas (sentry.io) Version 2.38.0 Steps to Reproduce This issue occurs when using OpenAI SDK and Sentry. If you try to cancel a task that is in the middle of processing ...
Opengraph URL: https://github.com/getsentry/sentry-python/issues/4853
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"asyncio.CancelledError exceptions are swallowed by capture_internal_exceptions()","articleBody":"### How do you use Sentry?\n\nSentry Saas (sentry.io)\n\n### Version\n\n2.38.0\n\n### Steps to Reproduce\n\nThis issue occurs when using OpenAI SDK and Sentry. If you try to cancel a task that is in the middle of processing OpenAI completion iterators, the task will never be cancelled because Sentry SDK is swallowing the exception.\n\nThis occurs in the following code:\nhttps://github.com/getsentry/sentry-python/blob/master/sentry_sdk/integrations/openai.py#L337-L370\n\nThe following code of course fixes the issue but it defeats the purpose of suppressing internal exceptions:\n\n```python\nclass CaptureInternalException:\n __slots__ = ()\n\n def __enter__(self):\n # type: () -> ContextManager[Any]\n return self\n\n def __exit__(self, ty, value, tb):\n # type: (Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]) -> bool\n if ty is not None and value is not None:\n capture_internal_exception((ty, value, tb))\n\n if isinstance(ty, asyncio.CancelledError): \u003c-------------------- ADDED\n return False\n\n return True\n```\n\nHowever, I believe `asyncio.CancelledError` is an special case that should be allowed.\n\n### Expected Result\n\nTask cancellations should work.\n\n### Actual Result\n\nTasks are never cancelled leaving applications in an invalid state.","author":{"url":"https://github.com/aconchillo","@type":"Person","name":"aconchillo"},"datePublished":"2025-09-24T01:33:45Z","url":"https://github.com/getsentry/sentry-python/issues/4853"}
| react-profiling | 0 |
| react-import-map | react,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-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ebcca2e4-cd0e-76b5-e1b6-50cca6363fc7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D57A:3CCE8:4EF085:6A4BED:6B00904C |
| html-safe-nonce | 10754e191dc55d6eca432f8d672ca964b50a86c003ef7dbdb41558e930cad1b5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENTdBOjNDQ0U4OjRFRjA4NTo2QTRCRUQ6NkIwMDkwNEMiLCJ2aXNpdG9yX2lkIjoiODY4Mzg0MDg4NDAzNjM3NDYwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 361932f27cb25409754f57a91fd92a4f0800aa42852eceb8b1f7977d8f3203d0 |
| hovercard-subject-tag | issue:3447217648 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-python/4853/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a4c0104d986e1110b2aec7765ad4a280428a4dd5eaaa1dbdea74c99992c0bf5e/getsentry/sentry-python/issues/4853 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a4c0104d986e1110b2aec7765ad4a280428a4dd5eaaa1dbdea74c99992c0bf5e/getsentry/sentry-python/issues/4853 |
| og:image:alt | How do you use Sentry? Sentry Saas (sentry.io) Version 2.38.0 Steps to Reproduce This issue occurs when using OpenAI SDK and Sentry. If you try to cancel a task that is in the middle of processing ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | aconchillo |
| hostname | github.com |
| expected-hostname | github.com |
| None | c710a5cb5c47be60abfe6e8410436d409906979dbed614ef09f29c60f5535b08 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-python git https://github.com/getsentry/sentry-python.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 137814779 |
| octolytics-dimension-repository_nwo | getsentry/sentry-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 137814779 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | be616a2a6ec1c609d6e002896dff5352d5c5f28b |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width