diff --git a/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py b/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py index b8531db17..721466d55 100644 --- a/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py +++ b/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py @@ -941,7 +941,12 @@ def _shutdown(self, reason: Any = None) -> None: assert self._leaser is not None self._leaser.stop() - total = len(dropped_messages) + len( + if dropped_messages is not None: + total = len(dropped_messages) + else: + total = 0 + + total = total + len( self._messages_on_hold._messages_on_hold ) _LOGGER.debug(f"NACK-ing all not-yet-dispatched messages (total: {total}).")