Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asserting throwing for async publish with currently errored batch #48

Closed
camerondavison opened this issue Mar 19, 2020 · 3 comments · Fixed by #49
Closed

asserting throwing for async publish with currently errored batch #48

camerondavison opened this issue Mar 19, 2020 · 3 comments · Fixed by #49
Assignees
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@camerondavison
Copy link

Environment details

  • OS type and version: linux
  • Python version: python --version : Python 3.7.6
  • pip version: pip --version : pip 19.3.1
  • google-cloud-pubsub version: pip show google-cloud-pubsub 1.3.1

Code example

from google.cloud import pubsub_v1
import time


def main():
    publisher = pubsub_v1.PublisherClient()
    topic_path = "projects/*****/topics/*****"

    try:
        publisher.publish(topic_path, data=b'')  # invalid
    except:
        pass

    while True:
        print('publishing')
        publisher.publish(topic_path, data=b'valid')
        time.sleep(1)


if __name__ == '__main__':
    main()

Stack trace

Traceback (most recent call last):
  File "pubsub_error.py", line 21, in <module>
    main()
  File "pubsub_error.py", line 16, in main
    publisher.publish(topic_path, data=b'valid')
  File "/Users/camerondavison/Library/Python/3.7/lib/python/site-packages/google/cloud/pubsub_v1/publisher/client.py", line 364, in publish
    future = sequencer.publish(message)
  File "/Users/camerondavison/Library/Python/3.7/lib/python/site-packages/google/cloud/pubsub_v1/publisher/_sequencer/unordered_sequencer.py", line 113, in publish
    future = batch.publish(message)
  File "/Users/camerondavison/Library/Python/3.7/lib/python/site-packages/google/cloud/pubsub_v1/publisher/_batch/thread.py", line 334, in publish
    ), "Publish after stop() or publish error."
AssertionError: Publish after stop() or publish error.

As I mentioned just now in #26 (comment) it looks like there is an assert that was added that can now trigger for an errored out batch.

batch errors could happen any time so it seems like it would be better to move the assert below the check to see if the batch is still accepting new messages so that a new batch can be created if it errored out.

I validated the same code does not throw an exception on publish in 1.2.0

@product-auto-label product-auto-label bot added the api: pubsub Issues related to the googleapis/python-pubsub API. label Mar 19, 2020
@yoshi-automation yoshi-automation added the triage me I really want to be triaged. label Mar 20, 2020
@pradn
Copy link
Contributor

pradn commented Mar 20, 2020

Cameron, thanks for the detailed bug report. I've just submitted a PR to fix the underlying issue.

@pradn
Copy link
Contributor

pradn commented Mar 20, 2020

We'll do a bugfix release early next week.

@plamut plamut added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. and removed triage me I really want to be triaged. labels Mar 20, 2020
@pradn pradn closed this as completed in #49 Mar 23, 2020
@pradn
Copy link
Contributor

pradn commented Mar 23, 2020

The fix is out in version 1.4.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: pubsub Issues related to the googleapis/python-pubsub API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants