Deepstream-app error(from source: Could not read from resource.) when unplugging and re-plugging the camera cable !

I run the deepstream5.0 app example on JetsonNX. When you reinsert the network cable, the following error occurs, causing the program to exit. This error seems to be caused by the failure to obtain the RTSP stream, and the probability of this error is high.

WARNING from source: Could not read from resource.
Debug info: gstrtspsrc.c(5293): gst_rtspsrc_loop_udp (): /GstPipeline:pipeline/GstBin:multi_src_bin/GstBin:src_sub_bin7/GstURIDecodeBin:src_elem/GstRTSPSrc:source:
Unhandled return value -7.
ERROR from source: Could not read from resource.
Debug info: gstrtspsrc.c(5361): gst_rtspsrc_loop_udp (): /GstPipeline:pipeline/GstBin:multi_src_bin/GstBin:src_sub_bin7/GstURIDecodeBin:src_elem/GstRTSPSrc:source:
Could not receive message. (System error)
ERROR from source: Internal data stream error.
Debug info: gstrtspsrc.c(5653): gst_rtspsrc_loop (): /GstPipeline:pipeline/GstBin:multi_src_bin/GstBin:src_sub_bin7/GstURIDecodeBin:src_elem/GstRTSPSrc:source:
streaming stopped, reason error (-5)
Quitting
App run failed

The system environment is as follows:

Jetpack: 4.5.1 (L4T 32.5.1)
deepstream-app version 5.0.0
DeepStreamSDK 5.0.0
CUDA Driver Version: 10.2
CUDA Runtime Version: 10.2
TensorRT Version: 7.1
cuDNN Version: 8.0
libNVWarp360 Version: 2.0.1d3
GStreamer Core Library version 1.14.5
libgstrtspserver-1.0-0 1.14.5-0ubuntu1~18.04.1

The main configuration files of the app are as follows:

[source0]
enable=1
## Type: 1=CameraV4L2 2=URI 3=MultiURI 4=RTSP
type=3
uri=rtsp://admin:1234@xx.xx.xx.xx:554/cam/realmonitor?channel=1&subtype=0
num-sources=1
camera-id=1
gpu-id=0
cudadec-memtype=0
drop-frame-interval=5

[source1]
enable=1
## Type: 1=CameraV4L2 2=URI 3=MultiURI 4=RTSP
type=3
uri=rtsp://admin:1234@xx.xx.xx.xx:554/cam/realmonitor?channel=1&subtype=0
num-sources=1
camera-id=2
gpu-id=0
cudadec-memtype=0
drop-frame-interval=5

[sink0]
enable=1
## Type: 1=FakeSink 2=EglSink 3=File 4=RTSPStreaming
type=2
sync=0
source-id=0
gpu-id=0
nvbuf-memory-type=0

[sink1]
enable=1
## Type: 1=FakeSink 2=EglSink 3=File 4=RTSPStreaming
type=4
rtsp-port=8554
udp-port=5400
sync=0
source-id=0
gpu-id=0
nvbuf-memory-type=0
## 1=h264 2=h265
codec=1
#encoder type 0=Hardware 1=Software
enc-type=0
bitrate=4000000
#H264 Profile - 0=Baseline 2=Main 4=High
#H265 Profile - 0=Main 1=Main10
profile=0

[osd]
enable=1
gpu-id=0
border-width=1
text-size=12
text-color=1;1;1;1;
text-bg-color=0.3;0.3;0.3;1
font=Serif
show-clock=0
clock-x-offset=800
clock-y-offset=820
clock-text-size=12
clock-color=1;0;0;0
nvbuf-memory-type=0

[streammux]
gpu-id=0
## Boolean property to inform muxer that sources are live
live-source=1
batch-size=4
batched-push-timeout=40000
## Set muxer output width and height
width=1280
height=720
enable-padding=0
nvbuf-memory-type=0

[primary-gie]
enable=1
gpu-id=0
model-engine-file=zj.engine
labelfile-path=labels-zj.txt
batch-size=4
#Required by the app for OSD, not a plugin property
bbox-border-color0=1;0;0;1
bbox-border-color1=0;1;1;1
bbox-border-color2=0;0;1;1
bbox-border-color3=0;1;0;1
interval=0
gie-unique-id=1
nvbuf-memory-type=0
config-file=config_infer_primary.txt

Also, if there are multiple cameras in the App Source configuration, but one of them is disconnected from the network. Running the deepstream-app program in this state causes the following error:

** INFO: <bus_callback:144>: Pipeline running

ERROR from source: Could not open resource for reading and writing.
Debug info: gstrtspsrc.c(7469): gst_rtspsrc_retrieve_sdp (): /GstPipeline:pipeline/GstBin:multi_src_bin/GstBin:src_sub_bin5/GstURIDecodeBin:src_elem/GstRTSPSrc:source:
Failed to connect. (Generic error)
Quitting
App run failed

deepstream-app does not support such kind of error handling. The camera driver is not implemented to report the unplugged error to v4l2 and gstreamer. So the app can not handle it. You need to write your own error handling logic according to your device.

However, when the video stream cannot be obtained or the stream is interrupted, can DS-APP not exit? Where should I modify it?

Did you still need support? if want DS-APP not exit, you can modify bus_callback in deepstream_app.c, set appCtx->quit to FALSE.