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

Nest integration failing due to aiohttp Network unreachable #44719

Closed
SlickUnderTheGun opened this issue Dec 31, 2020 · 17 comments
Closed

Nest integration failing due to aiohttp Network unreachable #44719

SlickUnderTheGun opened this issue Dec 31, 2020 · 17 comments
Assignees

Comments

@SlickUnderTheGun
Copy link

SlickUnderTheGun commented Dec 31, 2020

The problem

The Nest integration works properly for several hours (generally 2 to 3, longest was 21) and then fails to update changes to sensors and climate card. After the updates are no longer reported I am usually still able to use the climate card to make changes to target temperature, operation, and preset successfully (confirmed with Nest Android app). Occasionally making a change with the climate card after updates have failed results in a "Network unreachable" error. I am not sure if this is related or a separate issue.

Environment

  • Home Assistant Core release with the issue: 2020.12.0 and 2021.1.0.dev20201229
  • Last working Home Assistant Core release (if known):
  • Operating environment (OS/Container/Supervised/Core): Container
  • Integration causing this issue: Nest
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/nest/

Problem-relevant configuration.yaml

logger:
  default: warning
  logs:
    homeassistant.components.nest: debug
    homeassistant.components.nest.climate_sdm: debug
    homeassistant.components.nest.sensor_sdm: debug
    google_nest_sdm: debug
    google_nest_sdm.device: debug
    google_nest_sdm.device_manager: debug
    google_nest_sdm.google_nest_subscriber: debug
    google_nest_sdm.event: debug
    google.cloud.pubsub_v1: debug
    google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager: debug

nest:
  client_id: REDACTED
  client_secret: REDACTED
  project_id: REDACTED
  subscriber_id: projects/REDACTED/subscriptions/REDACTED

Traceback/Error logs

2020-12-31 08:00:13 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2020-12-31 08:00:14 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:14 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 2.206593 seconds.
2020-12-31 08:00:17 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:17 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 7.035542 seconds.
2020-12-31 08:00:24 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:24 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 4.837278 seconds.
2020-12-31 08:00:28 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:28 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 7.027480 seconds.
2020-12-31 08:00:35 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:35 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 2.337784 seconds.
2020-12-31 08:00:38 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:38 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 3.806416 seconds.
2020-12-31 08:00:42 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:42 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 7.189209 seconds.
2020-12-31 08:00:43 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2020-12-31 08:00:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 2.975245 seconds.
2020-12-31 08:00:52 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:52 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 2.729931 seconds.
2020-12-31 08:00:54 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:54 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 3.659996 seconds.
2020-12-31 08:00:58 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:58 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 0.583950 seconds.
2020-12-31 08:00:59 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:00:59 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 1.030404 seconds.
2020-12-31 08:01:00 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:01:00 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 3.772805 seconds.
2020-12-31 08:01:04 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:01:04 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 6.076978 seconds.
2020-12-31 08:01:10 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:01:10 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 0.705122 seconds.
2020-12-31 08:01:10 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2020-12-31 08:01:10 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 8.197921 seconds.
2020-12-31 08:01:13 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2020-12-31 08:01:15 INFO (Thread-76) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-terminating stream error 503 The service was unable to fulfill your request. Please try again. [code=8a75]
2020-12-31 08:01:15 INFO (Thread-76) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed recoverable stream error 503 The service was unable to fulfill your request. Please try again. [code=8a75]
2020-12-31 08:01:15 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-terminating stream error 503 The service was unable to fulfill your request. Please try again. [code=8a75]
2020-12-31 08:01:15 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed recoverable stream error 503 The service was unable to fulfill your request. Please try again. [code=8a75]
2020-12-31 08:01:15 INFO (Thread-76) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-terminating stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2020-12-31 08:01:15 INFO (Thread-76) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-recoverable stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2020-12-31 08:01:15 INFO (Thread-76) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] RPC termination has signaled streaming pull manager shutdown.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping consumer.
2020-12-31 08:01:15 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-terminating stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2020-12-31 08:01:15 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-recoverable stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping scheduler.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping leaser.
2020-12-31 08:01:15 INFO (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Thread-LeaseMaintainer exiting.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping dispatcher.
2020-12-31 08:01:15 DEBUG (Thread-CallbackRequestDispatcher) [google.cloud.pubsub_v1.subscriber._protocol.helper_threads] Exiting the QueueCallbackWorker.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping heartbeater.
2020-12-31 08:01:15 INFO (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Thread-Heartbeater exiting.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Finished stopping manager.
2020-12-31 08:01:15 DEBUG (Thread-OnRpcTerminated) [google_nest_sdm.google_nest_subscriber] Subscriber disconnected, will restart: <class 'google.api_core.exceptions.Unauthenticated'>: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2020-12-31 08:01:24 DEBUG (MainThread) [google_nest_sdm.google_nest_subscriber] Watchdog: subscriber shut down; restarting in 10 seconds

After the final log item there are no further messages from the integration until it is reloaded.

This is the error/traceback that is logged when the "Network unreachable" error occurs:

2020-12-31 14:17:18 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [2907568568] Access token failure: Cannot connect to host www.googleapis.com:443 ssl:default [Network unreachable]
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 975, in _wrap_create_connection
return await self._loop.create_connection(*args, **kwargs) # type: ignore # noqa
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1025, in create_connection
raise exceptions[0]
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 1010, in create_connection
sock = await self._connect_sock(
File "/usr/local/lib/python3.8/asyncio/base_events.py", line 924, in _connect_sock
await self.sock_connect(sock, address)
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 496, in sock_connect
return await fut
File "/usr/local/lib/python3.8/asyncio/selector_events.py", line 501, in _sock_connect
sock.connect(address)
OSError: [Errno 101] Network unreachable
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 44, in request
access_token = await self.async_get_access_token()
File "/usr/src/homeassistant/homeassistant/components/nest/api.py", line 28, in async_get_access_token
await self._oauth_session.async_ensure_token_valid()
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 465, in async_ensure_token_valid
new_token = await self.implementation.async_refresh_token(self.token)
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 84, in async_refresh_token
new_token = await self._async_refresh_token(token)
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 175, in _async_refresh_token
new_token = await self._token_request(
File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 193, in _token_request
resp = await session.post(self.token_url, data=data)
File "/usr/local/lib/python3.8/site-packages/aiohttp/client.py", line 527, in _request
conn = await self._connector.connect(
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 541, in connect
proto = await self._create_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 898, in _create_connection
_, proto = await self._create_direct_connection(req, traces, timeout)
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1057, in _create_direct_connection
raise last_exc
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 1026, in _create_direct_connection
transp, proto = await self._wrap_create_connection(
File "/usr/local/lib/python3.8/site-packages/aiohttp/connector.py", line 981, in _wrap_create_connection
raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host www.googleapis.com:443 ssl:default [Network unreachable]
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
await hass.services.async_call(
File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/nest/climate_sdm.py", line 308, in async_set_preset_mode
await trait.set_mode(PRESET_INV_MODE_MAP[preset_mode])
File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/thermostat_traits.py", line 38, in set_mode
return await self._cmd.execute(data)
File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/traits.py", line 23, in execute
resp = await self._auth.request(
File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 46, in request
raise AuthException(f"Access token failure: {err}") from err
google_nest_sdm.exceptions.AuthException: Access token failure: Cannot connect to host www.googleapis.com:443 ssl:default [Network unreachable]

Additional information

Using the reload option on the integrations page is always successful and the integration functions properly for several hours before failing again.

@probot-home-assistant
Copy link

nest documentation
nest source
(message by IssueLinks)

@probot-home-assistant
Copy link

Hey there @awarecan, @allenporter, mind taking a look at this issue as its been labeled with an integration (nest) you are listed as a codeowner for? Thanks!
(message by CodeOwnersMention)

@allenporter
Copy link
Contributor

@bdraco i was chatting with @SlickUnderTheGun on reddit about this one and was hoping you might have some insights here. This "network unreachable" thing seemed like it was related to aiohttp aio-libs/aiohttp#5112 however my impression was that you last upgraded aiohttp to include that fix. I was curious if you happeend to have seen anything like this before for other integrations. It seemed like odd symptoms where it mostly works then stops, and didn't seem like a typically "network connectivity" issue but something getting wedged. Any thoughts about how we can help or gather more data to diagnose this?

@allenporter
Copy link
Contributor

Kind of similar to aio-libs/aiohttp#2522 and I believe I hit this same issue when creating the nest sdm command line tool where it was ok to hack it up to get it working, but fix doesn't seem appropriate more generally

@allenporter allenporter changed the title Nest integration loses connection to API/fails to restart and stops updating Nest integration failing due to aiohttp Network unreachable Dec 31, 2020
@allenporter
Copy link
Contributor

@SlickUnderTheGun are you running under docker?

@bdraco
Copy link
Member

bdraco commented Jan 2, 2021

@bdraco i was chatting with @SlickUnderTheGun on reddit about this one and was hoping you might have some insights here. This "network unreachable" thing seemed like it was related to aiohttp aio-libs/aiohttp#5112 however my impression was that you last upgraded aiohttp to include that fix. I was curious if you happeend to have seen anything like this before for other integrations. It seemed like odd symptoms where it mostly works then stops, and didn't seem like a typically "network connectivity" issue but something getting wedged. Any thoughts about how we can help or gather more data to diagnose this?

It doesn't look like a case of 5112 as that was much more predictable. It might be related to aio-libs/aiohttp#5156 which is fixed in 3.7.2 (not possible to update to because of sendfile bugs that still need to be fixed) but that seems unlikely since there isn't an exception similar to the one shown in that issue.

Is ipv6 unreliable/broken on the system in question?

@allenporter
Copy link
Contributor

@bdraco thanks for looking.

It's true, when I saw this network unreachable problem it failed 100% of the time. I was able to upgrade to 3.7.3 and that let me remove the workarounds to force AF_INET:
allenporter/python-google-nest-sdm@b2d20a9

@SlickUnderTheGun in addition to the ipv6 question above, can you also confirm you have the latest version of aiohttp installed? with a command like:

$ pip3 list | grep aiohttp
aiohttp                       3.7.3

@bdraco
Copy link
Member

bdraco commented Jan 2, 2021

aio-libs/aiohttp#5157 regressed aio-libs/aiohttp#5125. My test wasn't good enough to catch it. That is what is blocking updating aiohttp (#42514) at the moment.

I haven't had a moment to unravel what needs to change to fix zero byte files again.

@SlickUnderTheGun
Copy link
Author

SlickUnderTheGun commented Jan 2, 2021

@SlickUnderTheGun are you running under docker?

I am.

Is ipv6 unreliable/broken on the system in question?

Not to my knowledge. I just never got around to enabling it. I can do that today if you'd like.

can you also confirm you have the latest version of aiohttp installed? with a command like:

sudo docker exec home-assistant pip3 list | grep aiohttp 

aiohttp                          3.7.1
aiohttp-cors                     0.7.0
WARNING: You are using pip version 20.2.4; however, version 20.3.3 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.

I can update packages within the container manually but when I pull a new docker image it'll revert to whatever version they're using so it wouldn't be an ideal solution.

@allenporter
Copy link
Contributor

@SlickUnderTheGun yeah, that is not a solution, just to help diagnose whats going on. Was curious if you had an even older version, or if its the same issue that was already fixed or something else. You're also welcome to wait for the latest aiohttp to be integrated fully though it may take awhile, or continue to diagnose the network issues.

@SlickUnderTheGun
Copy link
Author

I'm happy to continue to help troubleshoot until an acceptable solution has been found or you decide it isn't worth pursuing any further. I went ahead and enabled/configured IPv6 today and also updated my Home Assistant image to 2020.12.2. I'll send an update if the integration crashes or if it hasn't after a couple days. Let me know if you need any other information.

@SlickUnderTheGun
Copy link
Author

The integration ran from 2021-01-02 17:41:55 until 2021-01-03 22:26:23 EST and then failed again with these messages.

2021-01-03 22:26:13 INFO (Thread-829) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-recoverable stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2021-01-03 22:26:13 INFO (Thread-829) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] RPC termination has signaled streaming pull manager shutdown.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping consumer.
2021-01-03 22:26:13 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-terminating stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2021-01-03 22:26:13 INFO (Thread-ConsumeBidirectionalStream) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Observed non-recoverable stream error 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping scheduler.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping leaser.
2021-01-03 22:26:13 INFO (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Thread-LeaseMaintainer exiting.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping dispatcher.
2021-01-03 22:26:13 DEBUG (Thread-CallbackRequestDispatcher) [google.cloud.pubsub_v1.subscriber._protocol.helper_threads] Exiting the QueueCallbackWorker.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Stopping heartbeater.
2021-01-03 22:26:13 INFO (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Thread-Heartbeater exiting.
2021-01-03 22:26:13 DEBUG (Thread-OnRpcTerminated) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Finished stopping manager.
2021-01-03 22:26:13 WARNING (Thread-OnRpcTerminated) [google_nest_sdm.google_nest_subscriber] Subscriber disconnected, will restart: <class 'google.api_core.exceptions.Unauthenticated'>: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
2021-01-03 22:26:23 DEBUG (MainThread) [google_nest_sdm.google_nest_subscriber] Watchdog: subscriber shut down; restarting

I'll try to include some follow up information I think may be relevant.

I'm now getting this message in my logs. It occurs about every hour but sometimes I don't see it for 2-5 hours. The entire message will also sometimes repeat up to three times with the same timestamp. The integration continues to function normally so it does seem to be non-fatal as the message indicates. I'm including it because there's now a reference to IPv6 on line 12.

2021-01-03 21:23:14 DEBUG (Thread-CallbackRequestDispatcher) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Exception while sending unary RPC. This is typically non-fatal as stream requests are best-effort.
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.8/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.UNAUTHENTICATED
        details = "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project."
        debug_error_string = "{"created":"@1609726994.206401409","description":"Error received from peer ipv6:[2607:f8b0:4009:801::200a]:443","file":"src/core/lib/surface/call.cc","file_line":1061,"grpc_message":"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","grpc_status":16}"
>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 417, in send
    self._send_unary_request(request)
  File "/usr/local/lib/python3.8/site-packages/google/cloud/pubsub_v1/subscriber/_protocol/streaming_pull_manager.py", line 388, in _send_unary_request
    self._client.acknowledge(
  File "/usr/local/lib/python3.8/site-packages/google/cloud/pubsub_v1/_gapic.py", line 40, in <lambda>
    fx = lambda self, *a, **kw: wrapped_fx(self.api, *a, **kw)  # noqa
  File "/usr/local/lib/python3.8/site-packages/google/pubsub_v1/services/subscriber/client.py", line 909, in acknowledge
    rpc(
  File "/usr/local/lib/python3.8/site-packages/google/api_core/gapic_v1/method.py", line 145, in __call__
    return wrapped_func(*args, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 281, in retry_wrapped_func
    return retry_target(
  File "/usr/local/lib/python3.8/site-packages/google/api_core/retry.py", line 184, in retry_target
    return target()
  File "/usr/local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 59, in error_remapped_callable
    six.raise_from(exceptions.from_grpc_error(exc), exc)
  File "<string>", line 3, in raise_from
google.api_core.exceptions.Unauthenticated: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.

I also still get this message when trying to adjust the temperature with the Home Assistant climate card after the integration stops updating.

2021-01-03 23:24:24 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [2716375168] Access token failure: 400, message='Bad Request', url=URL('https://www.googleapis.com/oauth2/v4/token')
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 43, in request
    access_token = await self.async_get_access_token()
  File "/usr/src/homeassistant/homeassistant/components/nest/api.py", line 28, in async_get_access_token
    await self._oauth_session.async_ensure_token_valid()
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 465, in async_ensure_token_valid
    new_token = await self.implementation.async_refresh_token(self.token)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 84, in async_refresh_token
    new_token = await self._async_refresh_token(token)
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 175, in _async_refresh_token
    new_token = await self._token_request(
  File "/usr/src/homeassistant/homeassistant/helpers/config_entry_oauth2_flow.py", line 194, in _token_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.8/site-packages/aiohttp/client_reqrep.py", line 1002, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://www.googleapis.com/oauth2/v4/token')

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 135, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1445, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1480, in _execute_service
    await handler.job.target(service_call)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 204, in handle_service
    await self.hass.helpers.service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 593, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 664, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 630, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/climate/__init__.py", line 544, in async_service_temperature_set
    await entity.async_set_temperature(**kwargs)
  File "/usr/src/homeassistant/homeassistant/components/nest/climate_sdm.py", line 316, in async_set_temperature
    await trait.set_heat(temp)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/thermostat_traits.py", line 124, in set_heat
    return await self._cmd.execute(data)
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/traits.py", line 19, in execute
    resp = await self._auth.request(
  File "/usr/local/lib/python3.8/site-packages/google_nest_sdm/auth.py", line 45, in request
    raise AuthException(f"Access token failure: {err}") from err
google_nest_sdm.exceptions.AuthException: Access token failure: 400, message='Bad Request', url=URL('https://www.googleapis.com/oauth2/v4/token')

It may be completely unrelated but I have the Node-RED package node-red-contrib-home-assistant-websocket version 0.24.1 integrated with Home Assistant to handle all of my automations. I noticed that the integration failed about 10 minutes after a 'call service' node was used to change the temperature before we went to bed. I had this node disabled before the last time I updated Home Assistant (2021-01-02 17:41:55) but reenabled it yesterday. Is it possible that the Node-RED websocket call is somehow causing a problem with the Nest integration?

I've updated node-red-contrib-home-assistant-websocket to version 0.29.1, updated Node-RED from version 1.1.3 to 1.2.6, and restarted Home Assistant. I'll continue to test.

@allenporter
Copy link
Contributor

  1. The subscriber errors leading up to Watchdog: subscriber shut down; restarting are not a real problem. In 2020.01.XX the logs have been quieted to reduce the noise and/or confusion. Additionally, i rewrote how auth works to make the regular restarting not necessary. My impression is that you won't see any user visible problems due to this.
  2. The API calls (e.g. climate) unable to send RPCs to refresh creds due to your token being invalid are a problem.

This is all separate from the network unreachable of course.

@allenporter
Copy link
Contributor

@SlickUnderTheGun has your ipv6 work resolved your network unreachable errors?

@SlickUnderTheGun
Copy link
Author

@allenporter I'm not sure if it was enabling IPv6 or improvements you've made to your code but I believe it may be resolved. I pulled a new docker image which updated my Home Assistant version to 2021.2.0.dev20210101 at 2021-01-04 20:44:00 EST and the integration has updated continuously since, about 84 hours. Between then and now I have 189 instances of the Exception while sending unary RPC error, but not a single instance of homeassistant.helpers.config_entry_oauth2_flow in my logs (which I just confirmed is in my configuration and set to debug level).

It shouldn't cause too much trouble on my network to disable IPv6 again if you'd like to see if we can get the issue to repeat itself more reliably. Otherwise I'm going to leave my installation/container/configuration/etc. as is and continue to monitor the integration for a few days and then close the issue if there aren't any further problems.

@allistermaguire
Copy link
Contributor

@allenporter It looks like aiohttp was updated to 3.7.3 in release 2021.1.3 under a different MR to the one mentioned above.

@allenporter
Copy link
Contributor

@SlickUnderTheGun I didn't change anything, so lets assume it was your ipv6 adjustments and that aiohttp upgrade should fix it for anyone else running into this.

Thanks everyone!

@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants