home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.45k stars 30.69k forks source link

Synology Camera stops working on 0.65.3 #13139

Closed kolossboss closed 6 years ago

kolossboss commented 6 years ago

I updated pi 3 with Hassio to 0.65.3. My Synology Camera stops working. I restarted multiple times.

I see this in log.

2018-03-12 10:12:41 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform synology
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/synology/api.py", line 192, in _get_json_with_retry
    return self._get_json(url, payload)
  File "/usr/lib/python3.6/site-packages/synology/api.py", line 205, in _get_json
    raise SessionExpiredException('Session expired')
synology.api.SessionExpiredException: Session expired
fanaticDavid commented 6 years ago

I had a similar error earlier today:

2018-03-12 11:37:12 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform synology
Traceback (most recent call last):
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/api.py", line 192, in _get_json_with_retry
    return self._get_json(url, payload)
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/api.py", line 205, in _get_json
    raise SessionExpiredException('Session expired')
synology.api.SessionExpiredException: Session expired

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/srv/hass_venv/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py", line 82, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 245, in result
    raise self._exception
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 180, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/srv/hass_venv/lib/python3.6/site-packages/homeassistant/components/camera/synology.py", line 54, in async_setup_platform
    timeout=timeout
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/surveillance_station.py", line 16, in __init__
    self.update()
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/surveillance_station.py", line 20, in update
    cameras = self._api.camera_list()
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/api.py", line 101, in camera_list
    response = self._get_json_with_retry(api['url'], payload)
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/api.py", line 195, in _get_json_with_retry
    return self._get_json(url, payload)
  File "/srv/hass_venv/lib/python3.6/site-packages/synology/api.py", line 205, in _get_json
    raise SessionExpiredException('Session expired')
synology.api.SessionExpiredException: Session expired

I updated from 0.64.3 to 0.65.3 last night and everything was working fine. This morning I made an unrelated change to my config so I had to restart Home Assistant. The error above appeared after the restart, and my Synology-based camera's were broken. An additional restart of Home Assistant fixed the issue.

This issue must be caused by #13079. @snjoetw, any idea what could be causing this? @cmsimike, I take it you didn't encounter this issue during your testing. Have you updated to 0.65.3 as well?

Ironically, I never had issues with the Synology Surveillance Station platform before, even when Home Assistant had been running for 5+ days non-stop.

My setup:

cmsimike commented 6 years ago

My testing was fine. Had hass up for a few days each time with no issues. I think hass has been up now for 4-5 days (had a power outage last week).

I am currently still 0.64.3 the github install of the py-synology platform. .65 requires python 3.5.3, and im still only on 3.5.2 so will need to upgrade my python before i can get the new hass installed.

cmsimike commented 6 years ago

Looking through my logs on disk, it does seem like I'm getting the exception too, but it doesn't seem to change the synology camera behavior, meaning it is still working. That's why I never thought I had an issue with it.

Looking through the code:

    def _get_json_with_retry(self, url, payload):
        try:
            return self._get_json(url, payload)
        except SessionExpiredException:
            self._initialize_api_sid()
            return self._get_json(url, payload)

    def _get_json(self, url, payload):
        response = self._get(url, payload)
        content = response.json()

        if 'success' not in content or content['success'] is False:
            error_code = content.get('error', {}).get('code')

            if ERROR_CODE_SESSION_EXPIRED == error_code:
                raise SessionExpiredException('Session expired')

            raise ValueError('Invalid or failed response', content)

        return content

This block seems to be the only location of SessionExpiredException being thrown, and it seems to be getting caught. I don't know why it would be getting dumped to stdout. I thought you needed to explicitly print the exception or let it propagate all the way up?

I guess it is possible for _get_json to be throwing the exception twice in a row.

kolossboss commented 6 years ago

Today I restarted my Synology Diskstation because of a DSM Update. Now the cameras starts working again in Home Assistant. I'm not sure about the problem, because before the DS restart, all cameras works fine in the "Surveillance Station" but not in HA.

@fanaticDavid maybe you can try restarting too.

If this fix the problem, I close Issue

fanaticDavid commented 6 years ago

As I stated above:

My cameras never stopped working in Surveillance Station. Additionally, both DSM and the Surveillance Station package were already up-to-date at the time of the error.

Personally, I wouldn't close this issue just yet...

fanaticDavid commented 6 years ago

Just a quick update to report I haven't seen this error again, despite rebooting my RPi3 and restarting Home Assistant a few times. Maybe the session that expired was created prior to 0.65.x.

@kolossboss I think you can close this issue after all 🙂

kolossboss commented 6 years ago

👍