core: Synology camera stream auth expires
The problem
Camera streams from my Synology NAS appear to fail to authenticate after a period of time (1 hour?). When I add a fresh synology_dsm integration I can successfully authenticate and see all the cameras, their streams and other NAS information. After a while, at least an hour or more, the camera streams fail with the 401 Unauthorized error listed below. The static camera images and other NAS sensors continue to function without issue the whole time.
If I reload the synology_dsm integration, the streams immediately begin to work again.
Environment
- Home Assistant Core release with the issue: 0.117.4
- Last working Home Assistant Core release (if known): Not sure.
- Operating environment (OS/Container/Supervised/Core): Core / docker
- Integration causing this issue: synology_dsm
- Link to integration documentation on our website: https://www.home-assistant.io/integrations/synology_dsm/
Problem-relevant configuration.yaml
The integration was configured using the UI.
Traceback/Error logs
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 54, in stream_worker
_stream_worker_internal(hass, stream, quit_event)
File "/usr/src/homeassistant/homeassistant/components/stream/worker.py", line 71, in _stream_worker_internal
container = av.open(stream.source, options=stream.options, timeout=STREAM_TIMEOUT)
File "av/container/core.pyx", line 354, in av.container.core.open
File "av/container/core.pyx", line 225, in av.container.core.Container.__cinit__
File "av/container/core.pyx", line 257, in av.container.core.Container.err_check
File "av/error.pyx", line 336, in av.error.err_check
av.error.HTTPUnauthorizedError: [Errno 825242872] Server returned 401 Unauthorized (authorization failed): 'rtsp://syno:REDACTED@10.0.2.191:554/Sms=12.unicast'; last error log: [rtsp] method DESCRIBE failed: 401 Unauthorized
Additional information
I suspect, though have nothing to back this up, that this could be caused by one of two issues:
- The stream rtsp links aren’t refreshed whenever the API auth is refreshed; and/or
- The stream rtsp links are the 1 hour “temporary” streams that are available from the Surveillance Station UI and these expire and aren’t refreshed. See here for info on share stream link expiry.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 3
- Comments: 33 (17 by maintainers)
I think I might have a lead on this. In the Surveillance Station UI, there is a screen to grab a stream URL:
Surveillance Station > IP Camera > Right click on a camera > Share Stream Path
One of the settings in there is to set how long this link should be valid for - 1 hour or forever. I had assumed that these links were generated when you click save and the validity period was specific for that URL however it looks as though the validity period is for all streams - including those generated by the API.
It is possible that this default setting may have changed in a recent SS release as I don’t remember changing it to 1 hour and the stream URL’s previously did work forever.
If you go into that “Share Stream Path” window and change the validity period to forever, this bug doesn’t seem to happen any more.
I still think that this is a bug with the integration as a “401 Unauthorized” should be detected, reauthenticated and a new stream URL pulled from the API. What are everyone’s thoughts on that?
Hello @mib1185, Thanks, I have be using release 2021.4.6 for about a month now and I have not observed any Synology issues.
Hello @mib1185, I just started logging now with your latest version. For your information I am running Home Assistant version 2021.2.3 and I have the stream validity duration set to 1 hour for all three cameras. I will attach the results in a few days.
Update: I have attached a file that includes the section of the log file from the initial start and with the sections of the log file that had a Synology error. I missed any errors from the February 21 because I forgot I was recording the log and re-started HA for other reasons. synology_dsm_log02-20-21.txt
Hi @mib1185, The test is in progress. I will attach a text file of the debug log when done.
Update: I did not get any Synology errors during the 24 hour period. I did get some ‘Exceptions’ with my driveway camera, but maybe they are because it disconnects once and a while when the microwave is running. I had the stream validity duration set to 1 hour for most the the 24 hour period. I did change to a 24 hour stream validity duration for a few hours. I have attached a shortened version of the log that includes the first ~ 15 minutes of the log and the areas with exceptions because the whole log is 6.5MB. Let me know if you would like the entire log file.
synology_dsm_log_short.txt.
Hello @mib1185, Thanks for the tip. The testing was very easy using that approach. I have using your modified synology_dsm component for 12+ hours with no issues. I was able to access the camera live feeds many hours after I set the stream validity to one hour. The camera live feeds also worked fine with the stream validity set to forever. All the other monitors worked without any issues. There were 2 errors in the 14 hour period. I have included my log for this period.
@mib1185 The short report is that I tested the fix and it works with the cameras set to 1 hour stream validity! I did not use the docker image. I am using a virtual environment running version 0.118.4. So the way I tested the fix was as follows:
__init__.py, camera.py and switch.py files in the synology_dsm component folder with the ones from your link.__pycache__sub-directory.I did log some synology errors even when I was not accessing the live stream. I can attach my log since the reboot if you would like. I restarted Home-assistant again yesterday just to get a clean log. I have included the log errors associated with cameras and synology_dsm. The live stream feature has been solid when using the one hour stream validity setting.