Title: BackgroundConsumer destruction issues · Issue #788 · googleapis/python-api-core · GitHub
Open Graph Title: BackgroundConsumer destruction issues · Issue #788 · googleapis/python-api-core
X Title: BackgroundConsumer destruction issues · Issue #788 · googleapis/python-api-core
Description: We recently merged a PR that clears some variables that were causing a memory leak in the bidirectional streaming classes. It seems like after getting that fix in, it exposed a deeper issue: the background thread isn't exiting as expecte...
Open Graph Description: We recently merged a PR that clears some variables that were causing a memory leak in the bidirectional streaming classes. It seems like after getting that fix in, it exposed a deeper issue: the ba...
X Description: We recently merged a PR that clears some variables that were causing a memory leak in the bidirectional streaming classes. It seems like after getting that fix in, it exposed a deeper issue: the ba...
Opengraph URL: https://github.com/googleapis/python-api-core/issues/788
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"BackgroundConsumer destruction issues","articleBody":"We [recently merged a PR](https://github.com/googleapis/python-api-core/pull/770) that clears some variables that were causing a memory leak in the bidirectional streaming classes. It seems like after getting that fix in, it exposed a deeper issue: the [background thread isn't exiting as expected](https://github.com/googleapis/python-api-core/blob/34babf1a08219ff74c80d797352da760a760cd22/google/api_core/bidi.py#L719C1-L720C1).\n\n### Quick Fix\n\nWhen this happens, it's leading to a null pointer exception [here](https://github.com/googleapis/python-api-core/blob/34babf1a08219ff74c80d797352da760a760cd22/google/api_core/bidi.py#L667), now that the _on_response can be empty. So as a quick fix, we should add a None check there\n\n### Deeper Issue\n\nThe root issue is that the BackgroundConsumer's background thread is getting stuck calling [_on_response](https://github.com/googleapis/python-api-core/blob/34babf1a08219ff74c80d797352da760a760cd22/google/api_core/bidi.py#L667) while being torn down. In the case of Firestore, it looks like the deadlock is the fault of [the Watch class](https://github.com/googleapis/python-firestore/blob/main/google/cloud/firestore_v1/watch.py#L61), which tries to re-enter a lock. But I think we should consider changing the BackgroundConsumer to close quicker, without doing that final on_response call at all. Is it really necessary to call that callback while being closed?\n\n\n### More Context\nhttps://github.com/googleapis/python-firestore/issues/985#issuecomment-2622815245\n\nLet me know if you want me to submit a PR","author":{"url":"https://github.com/daniel-sanche","@type":"Person","name":"daniel-sanche"},"datePublished":"2025-02-01T00:27:37.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/788/python-api-core/issues/788"}
| 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:7ebce1c3-8a7b-486a-411c-59ac318b8abe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | EE36:CA906:10036A7:1718098:6A4E5461 |
| html-safe-nonce | 4f74f49c6c4a8cbf37920bdb193fe6809acaa2a9b4f3c73d96a0c5b2d9a55f83 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFRTM2OkNBOTA2OjEwMDM2QTc6MTcxODA5ODo2QTRFNTQ2MSIsInZpc2l0b3JfaWQiOiIzMzg1NDMxMTkxNzI1MTY3NzEzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a05e5b3fa612e7a617e6487acfe989e63531bc53695b2033077a02c3a1cbb7eb |
| hovercard-subject-tag | issue:2824633892 |
| 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/googleapis/python-api-core/788/issue_layout |
| twitter:image | https://opengraph.githubassets.com/99b2eef8cc3fef99a6d14deec333638b4366b6e86d427629620cb4f1af611600/googleapis/python-api-core/issues/788 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/99b2eef8cc3fef99a6d14deec333638b4366b6e86d427629620cb4f1af611600/googleapis/python-api-core/issues/788 |
| og:image:alt | We recently merged a PR that clears some variables that were causing a memory leak in the bidirectional streaming classes. It seems like after getting that fix in, it exposed a deeper issue: the ba... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | daniel-sanche |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-api-core git https://github.com/googleapis/python-api-core.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992456 |
| octolytics-dimension-repository_nwo | googleapis/python-api-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992456 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-api-core |
| 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 | f344f1eab54fc7dfc02d0d018cda7e158c3db65c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width