Skip to content

Conversation

@crimoniv
Copy link
Member

@crimoniv crimoniv commented Jul 23, 2025

🎩 What?

Try to achieve a graceful shutdown of the Worker by ensuring that SubscriberClient is properly closed, as we're still getting Cancelled messages even with the changes introduced in #295.

As an extra, this PR introduces some debug messages and test coverage (for this change and the previous one).

🤔 Why?

As per SubscriberClient documentation:

Must be used in a `with` block or have `__enter__()` called before use.

If we check the Python example provided in StreamingPull and high-level client library code samples, we can see that the subscriber is expected to the wrapped in a with block to automatically call close() when done:

# Wrap subscriber in a 'with' block to automatically call close() when done.
with subscriber:
    try:
        # When `timeout` is not set, result() will block indefinitely,
        # unless an exception is encountered first.
        streaming_pull_future.result(timeout=timeout)
    except TimeoutError:
        streaming_pull_future.cancel()  # Trigger the shutdown.
        streaming_pull_future.result()  # Block until the shutdown is complete.

🔗 Related issue

N/A

@crimoniv crimoniv changed the title Fix graceful worker shutdown [Fixed] Close subscriber on worker shutdown Jul 23, 2025
@crimoniv crimoniv merged commit 436f643 into master Jul 23, 2025
5 checks passed
@crimoniv crimoniv deleted the fix-graceful-worker-shutdown branch July 23, 2025 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants