ENT-1686/1687: Harden OpenCV RTSPS capture opens - #2792
Conversation
b3d41ea to
214abfb
Compare
a5db576 to
fb18db6
Compare
6c46903 to
a96eaf1
Compare
fb18db6 to
f1ff49c
Compare
a96eaf1 to
5d9ab74
Compare
f1ff49c to
cd32b96
Compare
|
🤖 Claude review started at commit New commits are not auto-reviewed. Add the |
0e66f1f to
62bd953
Compare
|
Re: High finding on
Branch rebased cleanly on #2776 ( |
|
🤖 Claude review started at commit New commits are not auto-reviewed. Add the |
1635761 to
27824fe
Compare
|
Follow-up from the lock discussion on #2776: dropped the process-wide USB/V4L2/file/plain RTSP opens are no longer serialized with RTSPS. The remaining lock is RTSPS-only ( Pushed in 93dad5c. |
Current situationAt the current #2792 head, The remaining lock is: _opencv_rtsps_tls_lock = threading.Lock()It applies only to RTSPS opens: This guarantees that two simultaneous RTSPS opens cannot overwrite or restore each other’s options incorrectly. The lock is held only while constructing What remains unsafeNon-RTSPS sources do not take the lock:
This means a non-RTSPS OpenCV/FFmpeg capture can open while the RTSPS environment is temporarily installed and observe options intended for the RTSPS source. For V4L2 this is generally irrelevant because it does not use FFmpeg. For files or plain RTSP using the FFmpeg backend, it can matter:
There is also an independent concurrency issue: The current implementation explicitly accepts these risks so that a stuck RTSPS camera cannot block an unrelated USB camera or file from opening. During the broad-lock implementationAn intermediate version introduced That solved both:
However, it also meant: Because those other backends do not necessarily have a bounded open timeout, one problematic source could stall all camera initialization or reconnection in the process. The broad lock was therefore removed, returning to the current RTSPS-only compromise. Long-term solutionThe correct architectural fix is to stop using a process-wide environment variable for per-source configuration. Preferred: a PyAV RTSPS producerPyAV supports per-instance FFmpeg options: av.open(
url,
options={
"rtsp_transport": "tcp",
"tls_verify": "1",
"cafile": ca_path,
"timeout": "5000000",
},
timeout=(5.0, read_timeout),
)This would provide:
It is especially sensible because PyAV is already a repository dependency. The cost is implementing a |
Wire opencv_rtsps_tls_env into CV2VideoFrameProducer so non-Jetson OpenCV/FFmpeg RTSPS opens honor rfdm-injected CA bundle and TLS flags. - Enter TLS env before capture_process_stderr (lock outside stderr redirect). - Widen helper signatures to Union[str, int] for the producer call site. - Document RTSPS-vs-RTSPS env isolation in the helper docstring.
Add module docstring for ROBOFLOW_RTSP_TLS_VALIDATION_FLAGS and CA bundle env vars (self-hosted escape hatch). Assert env var is restored after open, on capture failure, and untouched for int device indices.
OPENCV_FFMPEG_CAPTURE_OPTIONS and stderr dup2 are process-global, so concurrent camera opens can clobber each other. Hold one lock around the open.
A process-wide lock around every producer would stall USB/V4L2/file opens that have no FFmpeg timeout. Keep the RTSPS-only TLS env lock.
- Default FFmpeg stimeout and timeout (5s) to bound global TLS env lock hold. - Pin cv2.CAP_FFMPEG for rtsps:// so TLS options cannot be ignored. - Log when allow_self_signed (126) maps to full tls_verify=0 on FFmpeg.
A legacy env with only stimeout would skip timeout, which FFmpeg 5+ actually uses. Fill whichever key is missing.
93dad5c to
bb20812
Compare
Description
Hardens the OpenCV/FFmpeg RTSPS path wired in inference#2776 (ENT-1677).
Changes:
stimeout(5s) on RTSPS opens so one unreachable camera cannot hold the global TLS env lock for minutes.cv2.CAP_FFMPEGforrtsps://URLs soOPENCV_FFMPEG_CAPTURE_OPTIONScannot be silently ignored by another backend. Log a warning whentls_validation_flags=126(allow_self_signed) maps to fulltls_verify=0on FFmpeg (weaker than GStreamer's partial mode — documented, permanent product choice).Depends on: inference#2776 — merge that first, then this.
Linear: ENT-1686, ENT-1687
Type of change
How has this change been tested, please provide a testcase or example of how you tested the change?
test_build_options_rtsps_default_strict_verify— asserts default options includestimeout;5000000.test_cv2_producer_sets_ffmpeg_tls_options_only_for_rtspsfrom ENT-1677: Apply RTSPS TLS options to the OpenCV capture open #2776.Will the change affect Universe? If so was this change tested in universe?
No. Edge inference pipeline path only.
Any specific deployment considerations
Ship in the same inference release as #2776 (or immediately after). No config migrations.
Docs