GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — pubsub: Race condition in StreamingPullManager.shutdown — AttributeError: 'tuple' object has no attribute 'nack' and AssertionError · Issue #16125 · googleapis/google-cloud-python

pubsub: Race condition in StreamingPullManager.shutdown — AttributeError: 'tuple' object has no attribute 'nack' and AssertionError #16125

New issue
Copy link
New issue
Copy link
Open
Open
pubsub: Race condition in StreamingPullManager.shutdown — AttributeError: 'tuple' object has no attribute 'nack' and AssertionError#16125
Copy link
Assignees
abbrowne126
Labels
api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@christina-abridge
christina-abridge
opened on Mar 18, 2026
Issue body actions

Environment

  • google-cloud-pubsub >= 2.36.0
  • Python 3.12
  • StreamingPull with await_callbacks_on_shutdown=True
  • Source: packages/google-cloud-pubsub/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py

Description

During stream reconnection (server-initiated UNAVAILABLE), two threads race to execute _shutdown, and both crash:

Thread-RegularStreamShutdown (~line 1053):

File "streaming_pull_manager.py", line 1053, in _shutdown
    msg.nack()
AttributeError: 'tuple' object has no attribute 'nack'

Items in the internal message queue are raw tuples (not yet wrapped as Message objects), so calling .nack() fails.

Thread-OnRpcTerminated (~line 1026):

File "streaming_pull_manager.py", line 1026, in _shutdown
    assert self._scheduler is not None
AssertionError

The scheduler was already set to None by the other shutdown thread.

Impact

When both shutdown threads crash, pending messages in the internal queue are never nacked. They remain leased until expiry. Each lease expiry burns a delivery attempt against maxDeliveryAttempts, which can cause premature dead-lettering under autoscaling (frequent scale-up/down cycles).

Relation to googleapis/python-pubsub#997 / PR#1244

PR #1244 fixed the same assert self._scheduler is not None race in _on_response, but the identical pattern in _shutdown was not addressed. The tuple/nack issue in _shutdown is a separate bug not covered by that fix.

Suggested fix

  1. Replace the assert self._scheduler is not None in _shutdown with a None check + early return (same pattern as PR Adding list clusters request to Bigtable client. #1244).
  2. In the message nack loop, guard with hasattr(msg, 'nack') or isinstance before calling msg.nack() to handle raw tuples in the queue.

Reproduction

High-throughput StreamingPull subscriber with flow_control.max_messages=50-100 under frequent stream reconnections. The error appears in Python thread exception logs approximately once every few hours.

Reacted by Christian Bundy

Activity

  1. daniel-sanche
    assigned
    abbrowne126
    on Jun 15, 2026
  2. daniel-sanche
    added
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Jun 15, 2026
  3. daniel-sanche
    added
    api: pubsubIssues related to the Pub/Sub API.
    on Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @abbrowne126
    abbrowne126

Labels

api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.