Title: Long tasks lead to duplicate messages · Issue #593 · googleapis/python-pubsub · GitHub
Open Graph Title: Long tasks lead to duplicate messages · Issue #593 · googleapis/python-pubsub
X Title: Long tasks lead to duplicate messages · Issue #593 · googleapis/python-pubsub
Description: Hi, I'm having an issue where I have a long process (up to 80 minutes) running on a Kubernetes docker instance. The instance is running Ubuntu 20.04, and I'm using Python 3.8.10. The docker container runs a python worker script, which ru...
Open Graph Description: Hi, I'm having an issue where I have a long process (up to 80 minutes) running on a Kubernetes docker instance. The instance is running Ubuntu 20.04, and I'm using Python 3.8.10. The docker contain...
X Description: Hi, I'm having an issue where I have a long process (up to 80 minutes) running on a Kubernetes docker instance. The instance is running Ubuntu 20.04, and I'm using Python 3.8.10. The docker...
Opengraph URL: https://github.com/googleapis/python-pubsub/issues/593
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Long tasks lead to duplicate messages","articleBody":"Hi,\r\n\r\nI'm having an issue where I have a long process (up to 80 minutes) running on a Kubernetes docker instance. The instance is running Ubuntu 20.04, and I'm using Python 3.8.10. The docker container runs a python worker script, which runs a subprocess. The subprocess is multi-threaded and can use all threads during some CPU intensive tasks.\r\n\r\nI'm getting a lot of duplicates (about 5 to 10 duplicates). This is repeatable and probably due to the intense CPU usage. What is the correct way to handle this? Thanks in advance.\r\n\r\nMy pip versions are:\r\n\r\n```\r\ngoogle-api-core 1.30.0\r\ngoogle-api-python-client 2.38.0\r\ngoogle-auth 1.30.2\r\ngoogle-auth-httplib2 0.1.0\r\ngoogle-auth-oauthlib 0.4.4\r\ngoogle-cloud-core 1.7.0\r\ngoogle-cloud-firestore 2.3.4\r\ngoogle-cloud-pubsub 2.9.0\r\n```\r\n\r\nMy worker code is similar to this:\r\n\r\n```\r\nimport shutil\r\nimport argparse\r\nimport time\r\nimport json\r\nimport subprocess, shlex\r\nfrom pathlib import Path\r\nimport concurrent.futures\r\nfrom google.cloud import pubsub_v1\r\n\r\ndef run_command(cmd_title, cmd):\r\n\t\"\"\"Run command string as subprocess\"\"\"\r\n\ttry:\r\n\t\tcmd_list = shlex.split(cmd)\r\n\t\toutput = subprocess.run(cmd_list,check=True)\r\n\t\tprint (output)\r\n\texcept subprocess.CalledProcessError as e:\r\n\t\tprint ('Error running command ',str(cmd))\r\n\t\tprint (e.output)\r\n\t\tpass\r\n\r\n\treturn\r\n\r\ndef worker(\r\n\tproject_id,\r\n\tsubscription):\r\n\t''' receives messages from a pull subscription'''\r\n\r\n\t#create subscriber\r\n\tsubscriber = pubsub_v1.SubscriberClient()\r\n\tsubscription_path = subscriber.subscription_path(project_id, subscription)\r\n\tflow_control = pubsub_v1.types.FlowControl(\r\n\t\tmax_messages=1, \r\n\t\tmax_duration_per_lease_extension = 60,\r\n\t\tmax_lease_duration = 7200)\r\n\r\n\tdef callback(message):\r\n\t\tprint ('Received message {} of message ID {}'.format(message, message.message_id))\r\n\r\n\t\tcmd = '......'\r\n\t\trun_command('Long Task', cmd)\r\n\r\n\t\t#ack message\r\n\t\tmessage.ack()\r\n\t\tprint('Acknowledged message of message ID {}\\n'.format(message.message_id))\r\n\r\n\tfuture = subscriber.subscribe(subscription_path, callback=callback, flow_control=flow_control)\r\n\tprint('Listening for messages on {}..\\n'.format(subscription_path))\r\n\r\n\t# Wrap subscriber in a 'with' block to automatically call close() when done.\r\n\twith subscriber:\r\n\t\ttry:\r\n\t\t\t# When `timeout` is not set, result() will block indefinitely,\r\n\t\t\t# unless an exception is encountered first.\r\n\t\t\tfuture.result()\r\n\t\texcept:\r\n\t\t\tprint ('Exiting subscriber')\r\n\t\t\tfuture.cancel()\r\n\r\nif __name__ == '__main__':\r\n\tparser = argparse.ArgumentParser(description = 'Worker process')\r\n\tparser.add_argument('-p', '--project_id',default='project_id')\r\n\t\r\n\tparser.add_argument('-s', '--subscription', default='subscription')\r\n\targs = parser.parse_args()\r\n\r\n\t#run worker\r\n\tworker(args.project_id, args.subscription)\r\n```\r\n\r\nThanks in advance,","author":{"url":"https://github.com/jtressle","@type":"Person","name":"jtressle"},"datePublished":"2022-03-01T08:05:06Z","url":"https://github.com/googleapis/python-pubsub/issues/593"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:440ce188-58d7-afb4-4bad-f3244f4efacb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D97A:1A4904:19D32EE:236406C:6AEC568E |
| html-safe-nonce | 5dfb4753e973d99bafb1502309eb9843038be170ee07b000ead0e3aaf4d69f1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTdBOjFBNDkwNDoxOUQzMkVFOjIzNjQwNkM6NkFFQzU2OEUiLCJ2aXNpdG9yX2lkIjoiNTQ0MzE5MjgwMTEyMzM5MTExOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5bb402085f11ea38c7b2b5da4831597b1db302cba56296608be5eba038e62044 |
| hovercard-subject-tag | issue:1155001461 |
| 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-pubsub/593/issue_layout |
| twitter:image | https://opengraph.githubassets.com/aa6b78b82b38d91afa2a1d32ac9370779d6e023be47de37622b1b4075e76f279/googleapis/python-pubsub/issues/593 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/aa6b78b82b38d91afa2a1d32ac9370779d6e023be47de37622b1b4075e76f279/googleapis/python-pubsub/issues/593 |
| og:image:alt | Hi, I'm having an issue where I have a long process (up to 80 minutes) running on a Kubernetes docker instance. The instance is running Ubuntu 20.04, and I'm using Python 3.8.10. The docker contain... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jtressle |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3488dbe5257a92e2a716c5c60d82d398cf6def63a52378c4c79ede7ee87ab2b7 |
| turbo-cache-control | no-preview |
| go-import | github.com/googleapis/python-pubsub git https://github.com/googleapis/python-pubsub.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992581 |
| octolytics-dimension-repository_nwo | googleapis/python-pubsub |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992581 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-pubsub |
| 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 | 4bf5a08d17949149357af9350daf183c3e7e0a4d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width