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

Token refresh generate google api warning #10

Closed
fdebrus opened this issue May 9, 2024 · 6 comments
Closed

Token refresh generate google api warning #10

fdebrus opened this issue May 9, 2024 · 6 comments

Comments

@fdebrus
Copy link
Owner

fdebrus commented May 9, 2024

For each refresh as the watcher gets unsubcribe, a warning is generated. safe to ignore ? integration is working and token is being refreshed as it should.

async def refresh_listener(self):
    """Refresh the Firestore listener if token was refreshed."""
    if self.watch:
        _LOGGER.debug("Unsubscribing old listener")
        self.watch.unsubscribe()

    _LOGGER.debug("Re-subscribing with new token")
    await self.subscribe()

Logger: google.api_core.bidi
Source: custom_components/aquarite/aquarite.py:110
integration: Aquarite (documentation, issues)
First occurred: 3:55:42 PM (1 occurrences)
Last logged: 3:55:42 PM
Background thread did not exit.

@fdebrus fdebrus changed the title Toekn refresh generate google api warnings Token refresh generate google api warning May 9, 2024
@fdebrus fdebrus closed this as completed May 9, 2024
@fdebrus fdebrus reopened this May 9, 2024
@fdebrus
Copy link
Owner Author

fdebrus commented May 9, 2024

@fdebrus
Copy link
Owner Author

fdebrus commented May 9, 2024

I will catch the warning and only publish it in debug log if enabled. something like

async def refresh_listener(self):
    """Refresh the Firestore listener if token was refreshed."""
    if self.watch:
        try:
            with warnings.catch_warnings():
                warnings.simplefilter("error")
                _LOGGER.debug(f"Unsubscribing old listener: {self.watch}")
                self.watch.unsubscribe()
        except Warning as w:
            _LOGGER.debug(f"Ignored warning: {w}")

    _LOGGER.debug("Re-subscribing with new token")
    await self.subscribe()

OR

   warnings.filterwarnings("ignore", message="Background thread did not exit.*", category=UserWarning)

Will try and publish new release if confirmed stable

@fdebrus
Copy link
Owner Author

fdebrus commented May 9, 2024

Here is the debug log of google.api_core.bidi, will investigate

2024-05-09 19:22:07.847 INFO (MainThread) [google.cloud.firestore_v1.watch] RPC termination has signaled manager shutdown.
2024-05-09 19:22:07.849 DEBUG (Thread-6 (_run)) [google.api_core.bidi] Cleanly exiting request generator.
2024-05-09 19:22:07.850 DEBUG (Thread-ConsumeBidirectionalStream) [google.api_core.bidi] Call to retryable <bound method ResumableBidiRpc._recv of <google.api_core.bidi.ResumableBidiRpc object at 0x7fbb2888fd10>> caused <_MultiThreadedRendezvous of RPC that terminated with:
2024-05-09 19:22:07.850 DEBUG (Thread-ConsumeBidirectionalStream) [google.api_core.bidi] Terminating <bound method ResumableBidiRpc._recv of <google.api_core.bidi.ResumableBidiRpc object at 0x7fbb2888fd10>> due to <_MultiThreadedRendezvous of RPC that terminated with:
2024-05-09 19:22:07.851 DEBUG (Thread-ConsumeBidirectionalStream) [google.api_core.bidi] recved response.
2024-05-09 19:22:08.850 WARNING (MainThread) [google.api_core.bidi] Background thread did not exit.
2024-05-09 19:22:08.857 DEBUG (MainThread) [google.api_core.bidi] Started helper thread Thread-ConsumeBidirectionalStream
2024-05-09 19:22:08.858 INFO (Thread-ConsumeBidirectionalStream) [google.api_core.bidi] Thread-ConsumeBidirectionalStream exiting

@fdebrus
Copy link
Owner Author

fdebrus commented May 9, 2024

Filtered the warning from being displayed in the log. Still investigating if this is confirmed to be safe to ignore.

@fdebrus
Copy link
Owner Author

fdebrus commented May 10, 2024

The logging is coming from the BackgroundConsumer.stop method in google/api_core/bidi.py:

def stop(self):
    """Stop consuming the stream and shutdown the background thread."""
    with self._operational_lock:
        self._bidi_rpc.close()

        if self._thread is not None:
            # Resume the thread to wake it up in case it is sleeping.
            self.resume()
            # The daemonized thread may itself block, so don't wait
            # for it longer than a second.
            self._thread.join(1.0)
            if self._thread.is_alive():  # pragma: NO COVER
                _LOGGER.warning("Background thread did not exit.")

        self._thread = None

According my various reading, this is safe to ignore.

@fdebrus
Copy link
Owner Author

fdebrus commented May 10, 2024

Solved in 0.0.9b2, safe to ignore warning. Logging level set to ERROR for api_core.bidi

suppress warning message from google.api_core.bidi

logger = logging.getLogger('google.api_core.bidi')
logger.setLevel(logging.ERROR)

@fdebrus fdebrus closed this as completed May 10, 2024
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

No branches or pull requests

1 participant