Hi,
We would suggest destroy the gstreamer pipeline when the camera is disconnected. And re-initialize the pipeline the the camera is connected. If the source is nvarguscamerasrc plugin, please refer to the samples:
GStreamer freeze when using qtmux and NVIDIA-accelerated h264/h265 encoding - #7 by DaneLLL
GStreamer C++ nvarguscamerasrc - #5 by DaneLLL