René's URL Explorer Experiment


Title: PubSub: Unexpected behavior for 2 or more subscribes with the same scheduler · Issue #11 · googleapis/python-pubsub · GitHub

Open Graph Title: PubSub: Unexpected behavior for 2 or more subscribes with the same scheduler · Issue #11 · googleapis/python-pubsub

X Title: PubSub: Unexpected behavior for 2 or more subscribes with the same scheduler · Issue #11 · googleapis/python-pubsub

Description: Environment details OS: Ubuntu 18.04.3 LTS Python version: 3.7.4 google-cloud-pubsub version: 1.0.2 Steps to reproduce Set up a GCP project with enabled Pub/Sub and set up local environment so that the scripts can connect to it. Run serv...

Open Graph Description: Environment details OS: Ubuntu 18.04.3 LTS Python version: 3.7.4 google-cloud-pubsub version: 1.0.2 Steps to reproduce Set up a GCP project with enabled Pub/Sub and set up local environment so that...

X Description: Environment details OS: Ubuntu 18.04.3 LTS Python version: 3.7.4 google-cloud-pubsub version: 1.0.2 Steps to reproduce Set up a GCP project with enabled Pub/Sub and set up local environment so that...

Opengraph URL: https://github.com/googleapis/python-pubsub/issues/11

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PubSub: Unexpected behavior for 2 or more subscribes with the same scheduler","articleBody":"#### Environment details\r\n\r\nOS: Ubuntu 18.04.3 LTS\r\nPython version: 3.7.4\r\ngoogle-cloud-pubsub version: 1.0.2\r\n\r\n#### Steps to reproduce\r\n\r\n  1. Set up a GCP project with enabled Pub/Sub and set up local environment so that the scripts can connect to it.\r\n  2. Run `server.py` (in code examples below). It should create 2 topics (`topic_a` and `topic_b`) and subscriptions to them and start listening to those subscriptions. Notice that scheduler is passed as an argument to receive messages (documentation does not indicate that this should cause any troubles)\r\n 3. Open a new terminal window and run `python3.7 client.py topic_a \u0026` and `python3.7 client.py topic_b \u0026`. This should start sending messages to both topics. (code in the examples below)\r\n 4. The server will output some details about all published messages on both topics. Look at the unacked messages on both subscriptions in the GCP console or stack driver. You will see that some messages are still in the pubsub (which ones is quite random). If you try to pull them, nothing is returned.\r\n 5. Terminate the running server.\r\n 6. Pull messages from either subscription - you should be able to retrieve all of them. Notice that these messages have been processed by the server, but it is as if the `ack` did nothing.\r\n 7. If you restart the server, it will process some of the messages again and some may even be acked out of the subscription. \r\n\r\nWhole time there are no error logs or exceptions thrown, messages are just stuck in the subscription even after being acked. If you change the server code to instantiate thread scheduler inside of the `receive_messages` function, everything works as expected, therefore the shared scheduler is the problem.\r\n\r\n#### Code example\r\n\r\nserver.py\r\n```python\r\nimport concurrent.futures.thread\r\nimport os\r\nimport time\r\n\r\nfrom google.api_core.exceptions import AlreadyExists\r\nfrom google.cloud import pubsub_v1\r\nfrom google.cloud.pubsub_v1.subscriber.scheduler import ThreadScheduler\r\n\r\n\r\ndef create_subscription(project_id, topic_name, subscription_name):\r\n    \"\"\"Create a new pull subscription on the given topic.\"\"\"\r\n    subscriber = pubsub_v1.SubscriberClient()\r\n    topic_path = subscriber.topic_path(project_id, topic_name)\r\n    subscription_path = subscriber.subscription_path(\r\n        project_id, subscription_name)\r\n\r\n    subscription = subscriber.create_subscription(\r\n        subscription_path, topic_path)\r\n\r\n    print('Subscription created: {}'.format(subscription))\r\n\r\n\r\ndef receive_messages(project_id, subscription_name, t_scheduler):\r\n    \"\"\"Receives messages from a pull subscription.\"\"\"\r\n    subscriber = pubsub_v1.SubscriberClient()\r\n    subscription_path = subscriber.subscription_path(\r\n        project_id, subscription_name)\r\n\r\n    def callback(message):\r\n        print('Received message: {}'.format(message.data))\r\n        message.ack()\r\n\r\n    subscriber.subscribe(subscription_path, callback=callback, scheduler=t_scheduler)\r\n    print('Listening for messages on {}'.format(subscription_path))\r\n\r\n\r\nproject_id = os.getenv(\"PUBSUB_PROJECT_ID\")\r\n\r\npublisher = pubsub_v1.PublisherClient()\r\nproject_path = publisher.project_path(project_id)\r\n\r\n# Create both topics\r\ntry:\r\n    topics = [topic.name.split('/')[-1] for topic in publisher.list_topics(project_path)]\r\n    if 'topic_a' not in topics:\r\n        publisher.create_topic(publisher.topic_path(project_id, 'topic_a'))\r\n    if 'topic_b' not in topics:\r\n        publisher.create_topic(publisher.topic_path(project_id, 'topic_b'))\r\nexcept AlreadyExists:\r\n    print('Topics already exists')\r\n\r\n# Create subscriptions on both topics\r\nsub_client = pubsub_v1.SubscriberClient()\r\nproject_path = sub_client.project_path(project_id)\r\n\r\ntry:\r\n    subs = [sub.name.split('/')[-1] for sub in sub_client.list_subscriptions(project_path)]\r\n    if 'topic_a_sub' not in subs:\r\n        create_subscription(project_id, 'topic_a', 'topic_a_sub')\r\n    if 'topic_b_sub' not in subs:\r\n        create_subscription(project_id, 'topic_b', 'topic_b_sub')\r\nexcept AlreadyExists:\r\n    print('Subscriptions already exists')\r\n\r\nscheduler = ThreadScheduler(concurrent.futures.thread.ThreadPoolExecutor(10))\r\n\r\nreceive_messages(project_id, 'topic_a_sub', scheduler)\r\nreceive_messages(project_id, 'topic_b_sub', scheduler)\r\n\r\nwhile True:\r\n    time.sleep(60)\r\n```\r\n\r\nclient.py\r\n```python\r\nimport datetime\r\nimport os\r\nimport random\r\nimport sys\r\nfrom time import sleep\r\n\r\nfrom google.cloud import pubsub_v1\r\n\r\n\r\ndef publish_messages(pid, topic_name):\r\n    \"\"\"Publishes multiple messages to a Pub/Sub topic.\"\"\"\r\n    publisher = pubsub_v1.PublisherClient()\r\n    topic_path = publisher.topic_path(pid, topic_name)\r\n\r\n    for n in range(1, 10):\r\n        data = '[{} - {}] Message number {}'.format(datetime.datetime.now().isoformat(), topic_name, n)\r\n        data = data.encode('utf-8')\r\n        publisher.publish(topic_path, data=data)\r\n        sleep(random.randint(10, 50) / 10.0)\r\n\r\n\r\nproject_id = os.getenv(\"PUBSUB_PROJECT_ID\")\r\npublish_messages(project_id, sys.argv[1])\r\n```\r\n\r\nI have created the [stack overflow thread](https://stackoverflow.com/questions/58289804/gcp-message-stays-in-the-pub-sub-after-acknowledge/58313340#58313340) first, then did my own testing. \r\n\r\n\r\nI would expect that using the same scheduler would not cause any difference in behavior or at the very least some exceptions or warnings to be raised that would indicate that something is wrong. \r\n\r\nAlso, it might be a good idea to warn people not to use the same scheduler for multiple subscriptions (even to different topics) somewhere in the documentation of the library. Due to the nature of the issue (no obvious indication that something is wrong), it might get to production quite easily. ","author":{"url":"https://github.com/LukasSlouka","@type":"Person","name":"LukasSlouka"},"datePublished":"2019-10-17T12:35:15.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/11/python-pubsub/issues/11"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:e467ff01-ae58-1020-c577-d988400fde69
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idBD10:9609B:193BD40:247CCC8:6A4CF27C
html-safe-nonce6c6a32ab8b0ba9be260d3722dd08e6763900e56ea33eedfe7bc6078078959659
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRDEwOjk2MDlCOjE5M0JENDA6MjQ3Q0NDODo2QTRDRjI3QyIsInZpc2l0b3JfaWQiOiI1NTgyMzkwNTIyMjE3ODIwNzk2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac26230529341e66c4f800964dab742529d93f95185b2f14c93187c163d9a3aca7
hovercard-subject-tagissue:558132800
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/googleapis/python-pubsub/11/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c1abb086c574ac77da69ea137aa40e1f23ca66b920a835890607059737cb59ee/googleapis/python-pubsub/issues/11
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c1abb086c574ac77da69ea137aa40e1f23ca66b920a835890607059737cb59ee/googleapis/python-pubsub/issues/11
og:image:altEnvironment details OS: Ubuntu 18.04.3 LTS Python version: 3.7.4 google-cloud-pubsub version: 1.0.2 Steps to reproduce Set up a GCP project with enabled Pub/Sub and set up local environment so that...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameLukasSlouka
hostnamegithub.com
expected-hostnamegithub.com
None299b43bca6e02ad35197ffeba30d2466846d5fb02ab96fbced5b5e6cec589fb8
turbo-cache-controlno-preview
go-importgithub.com/googleapis/python-pubsub git https://github.com/googleapis/python-pubsub.git
octolytics-dimension-user_id16785467
octolytics-dimension-user_logingoogleapis
octolytics-dimension-repository_id226992581
octolytics-dimension-repository_nwogoogleapis/python-pubsub
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id226992581
octolytics-dimension-repository_network_root_nwogoogleapis/python-pubsub
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
releaseefec6750a5afcaeaf5dfcf629f404cf98c8371e3
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/googleapis/python-pubsub/issues/11#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-pubsub%2Fissues%2F11
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fgoogleapis%2Fpython-pubsub%2Fissues%2F11
Sign up https://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=googleapis%2Fpython-pubsub
Reloadhttps://github.com/googleapis/python-pubsub/issues/11
Reloadhttps://github.com/googleapis/python-pubsub/issues/11
Reloadhttps://github.com/googleapis/python-pubsub/issues/11
Please reload this pagehttps://github.com/googleapis/python-pubsub/issues/11
googleapis https://github.com/googleapis
python-pubsubhttps://github.com/googleapis/python-pubsub
Notifications https://github.com/login?return_to=%2Fgoogleapis%2Fpython-pubsub
Fork 214 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-pubsub
Star 430 https://github.com/login?return_to=%2Fgoogleapis%2Fpython-pubsub
Code https://github.com/googleapis/python-pubsub
Issues 0 https://github.com/googleapis/python-pubsub/issues
Pull requests 0 https://github.com/googleapis/python-pubsub/pulls
Actions https://github.com/googleapis/python-pubsub/actions
Projects https://github.com/googleapis/python-pubsub/projects
Security and quality 0 https://github.com/googleapis/python-pubsub/security
Insights https://github.com/googleapis/python-pubsub/pulse
Code https://github.com/googleapis/python-pubsub
Issues https://github.com/googleapis/python-pubsub/issues
Pull requests https://github.com/googleapis/python-pubsub/pulls
Actions https://github.com/googleapis/python-pubsub/actions
Projects https://github.com/googleapis/python-pubsub/projects
Security and quality https://github.com/googleapis/python-pubsub/security
Insights https://github.com/googleapis/python-pubsub/pulse
#100https://github.com/googleapis/python-pubsub/pull/100
PubSub: Unexpected behavior for 2 or more subscribes with the same schedulerhttps://github.com/googleapis/python-pubsub/issues/11#top
#100https://github.com/googleapis/python-pubsub/pull/100
https://github.com/pradn
api: pubsubIssues related to the googleapis/python-pubsub API.https://github.com/googleapis/python-pubsub/issues?q=state%3Aopen%20label%3A%22api%3A%20pubsub%22
type: docsImprovement to the documentation for an API.https://github.com/googleapis/python-pubsub/issues?q=state%3Aopen%20label%3A%22type%3A%20docs%22
https://github.com/LukasSlouka
LukasSloukahttps://github.com/LukasSlouka
on Oct 17, 2019https://github.com/googleapis/python-pubsub/issues/11#issue-558132800
stack overflow threadhttps://stackoverflow.com/questions/58289804/gcp-message-stays-in-the-pub-sub-after-acknowledge/58313340#58313340
pradnhttps://github.com/pradn
api: pubsubIssues related to the googleapis/python-pubsub API.https://github.com/googleapis/python-pubsub/issues?q=state%3Aopen%20label%3A%22api%3A%20pubsub%22
type: docsImprovement to the documentation for an API.https://github.com/googleapis/python-pubsub/issues?q=state%3Aopen%20label%3A%22type%3A%20docs%22
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.