mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-24 07:24:42 +03:00
return a 500 instead of raising when go2rtc is unreachable
The two go2rtc stream GETs had no exception handling or timeout, so a go2rtc outage raised a connection error with a traceback, and a hung go2rtc held the request open indefinitely. Both now catch request errors, log the cause, and use a timeout. The per-stream probe gets a 35s read timeout because go2rtc probes each source in turn, and one unresponsive source takes about 10s.
This commit is contained in:
+23
-14
@@ -84,9 +84,13 @@ def _is_valid_host(host: str) -> bool:
|
|||||||
|
|
||||||
@router.get("/go2rtc/streams", dependencies=[Depends(allow_any_authenticated())])
|
@router.get("/go2rtc/streams", dependencies=[Depends(allow_any_authenticated())])
|
||||||
async def go2rtc_streams(request: Request):
|
async def go2rtc_streams(request: Request):
|
||||||
r = await asyncio.to_thread(requests.get, "http://127.0.0.1:1984/api/streams")
|
try:
|
||||||
if not r.ok:
|
r = await asyncio.to_thread(
|
||||||
logger.error("Failed to fetch streams from go2rtc")
|
requests.get, "http://127.0.0.1:1984/api/streams", timeout=10
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
except requests.RequestException as e:
|
||||||
|
logger.error("Failed to fetch streams from go2rtc: %s", e)
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content=({"success": False, "message": "Error fetching stream data"}),
|
content=({"success": False, "message": "Error fetching stream data"}),
|
||||||
status_code=500,
|
status_code=500,
|
||||||
@@ -121,16 +125,21 @@ async def go2rtc_streams(request: Request):
|
|||||||
dependencies=[Depends(require_go2rtc_stream_access)],
|
dependencies=[Depends(require_go2rtc_stream_access)],
|
||||||
)
|
)
|
||||||
def go2rtc_camera_stream(request: Request, stream_name: str):
|
def go2rtc_camera_stream(request: Request, stream_name: str):
|
||||||
r = requests.get(
|
try:
|
||||||
"http://127.0.0.1:1984/api/streams",
|
r = requests.get(
|
||||||
params={
|
"http://127.0.0.1:1984/api/streams",
|
||||||
"src": stream_name,
|
params={
|
||||||
"video": "all",
|
"src": stream_name,
|
||||||
"audio": "all",
|
"video": "all",
|
||||||
"microphone": "",
|
"audio": "all",
|
||||||
},
|
"microphone": "",
|
||||||
)
|
},
|
||||||
if not r.ok:
|
# go2rtc probes each source in turn, so one unresponsive source
|
||||||
|
# can take 10s or more
|
||||||
|
timeout=(2, 35),
|
||||||
|
)
|
||||||
|
r.raise_for_status()
|
||||||
|
except requests.RequestException as e:
|
||||||
camera_config = request.app.frigate_config.cameras.get(stream_name)
|
camera_config = request.app.frigate_config.cameras.get(stream_name)
|
||||||
|
|
||||||
if camera_config is None:
|
if camera_config is None:
|
||||||
@@ -140,7 +149,7 @@ def go2rtc_camera_stream(request: Request, stream_name: str):
|
|||||||
break
|
break
|
||||||
|
|
||||||
if camera_config and camera_config.enabled:
|
if camera_config and camera_config.enabled:
|
||||||
logger.error("Failed to fetch streams from go2rtc")
|
logger.error("Failed to fetch streams from go2rtc: %s", e)
|
||||||
|
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
content=({"success": False, "message": "Error fetching stream data"}),
|
content=({"success": False, "message": "Error fetching stream data"}),
|
||||||
|
|||||||
Reference in New Issue
Block a user