black-roland / homeassistant-microsoft-todo

The integration allows you to create tasks in Microsoft To Do from Home Assistant.
MIT License
110 stars 8 forks source link

Failed request flooding #57

Open aetha opened 3 years ago

aetha commented 3 years ago

After my Home Assistant has been running for about an hour, automatic attempts to sync my to-do lists are failing, and immediately retried. This is resulting in a constant flood of requests, I’m seeing up to 7 per second. This doesn’t seem to stop as long as it’s running. Here’s one of them.

2021-04-17 08:41:30 ERROR (SyncWorker_15) [custom_components.microsoft_todo.calendar] Unable to get tasks: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/beta/me/outlook/taskFolders/xxx/tasks?%24filter=status+ne+%27completed%27&%24top=100. Response: {'error': {'code': 'InvalidAuthenticationToken', 'message': 'Unable to initialize RPS', 'innerError': {'date': '2021-04-16T22:41:30', 'request-id': 'xxx', 'client-request-id': 'xxx'}}}
2021-04-17 08:41:30 ERROR (MainThread) [homeassistant.helpers.entity] Update for calendar.tasks fails
Traceback (most recent call last):
File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 292, in async_update_ha_state
await self.async_device_update()
File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity.py", line 490, in async_device_update
raise exc
File "/usr/lib/python3.8/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/util/__init__.py", line 278, in wrapper
result = method(*args, **kwargs)
File "/home/ha-arcana/.homeassistant/custom_components/microsoft_todo/calendar.py", line 234, in update
tasks_res = self._tasks_api.get_uncompleted_tasks(self._list_id)
File "/home/ha-arcana/.homeassistant/custom_components/microsoft_todo/outlook_tasks_api.py", line 65, in get_uncompleted_tasks
res.raise_for_status()
File "/opt/homeassistant/lib/python3.8/site-packages/requests/models.py", line 943, in raise_for_status
raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://graph.microsoft.com/beta/me/outlook/taskFolders/xxx/tasks?%24filter=status+ne+%27completed%27&%24top=100

Perhaps maybe the large number of lists I have (27) could be causing some kind of rate limiting, or race condition. Really got no idea though.

black-roland commented 3 years ago

Hmm, I found a similar discussion on Microsoft Q&A https://docs.microsoft.com/en-us/answers/questions/360116/commicrosoftgraphhttpgraphserviceexception-error-c.html And also a few mentions of the same issue but when working with OneDrive.

But this is weird anyway because API should return 429 error when hitting the RPS limit, not 401 https://docs.microsoft.com/en-us/graph/throttling :thinking:

I don't have this error in my logs but I'll continue monitoring and hopefully will find the root cause.