Crash in cuvidCreateDecoder

I have an app that crashes randomly in time but in one place. The call stack is:

#0  0x00007f53ac481228 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#1  0x00007f53ac48135b in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#2  0x00007f53ac4825fb in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#3  0x00007f53ac46ac05 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#4  0x00007f53ac46aea0 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#5  0x00007f53ac4528d6 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#6  0x00007f53ac45d437 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#7  0x00007f53ac45a0df in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#8  0x00007f53ac455cda in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#9  0x00007f53ac454ba7 in cuvidCreateDecoder () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#10 0x00007f53acb0eb5b in cuvidv4l2_handle_video_sequence_cb(void*, CUVIDEOFORMAT*) () at ///opt/nvidia/deepstream/deepstream-4.0/lib/libcuvidv4l2.so
#11 0x00007f53ac44f680 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#12 0x00007f53ac4a4560 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#13 0x00007f53ac48de2b in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#14 0x00007f53ac48fe06 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#15 0x00007f53ac4a4937 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#16 0x00007f53ac4a4f98 in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#17 0x00007f53ac44f41b in  () at /usr/lib/x86_64-linux-gnu/libnvcuvid.so.1
#18 0x00007f53acb12d64 in cuvidv4l2_dec_enqueue_instream_buffers(v4l2_decoder_context_rec*) () at ///opt/nvidia/deepstream/deepstream-4.0/lib/libcuvidv4l2.so
#19 0x00007f53acb1309a in cuvidv4l2_dec_thread_func(void*) () at ///opt/nvidia/deepstream/deepstream-4.0/lib/libcuvidv4l2.so
#20 0x00007f53acb01b30 in thread_wrapper(void*) () at ///opt/nvidia/deepstream/deepstream-4.0/lib/libcuvidv4l2.so
#21 0x00007f54647c46db in start_thread () at /lib/x86_64-linux-gnu/libpthread.so.0
#22 0x00007f5462bc471f in clone () at /lib/x86_64-linux-gnu/libc.so.6

That happens while another thread is always deep in gst_element_change_state(… NULL) for a bin that contains a video source reader/parser/decoder.

Do you have any recomendations on how to debug/fix this? Thank you!

**• Hardware Platform - GTX 1080 **
**• DeepStream Version - 4.0.2 **
**• NVIDIA GPU Driver Version (valid for GPU only) - 460.32.03 **

First, deepstream 4.0 is out of date, please upgrade to latest deepstream version DeepStream Getting Started | NVIDIA Developer

From the error log, we can only know something wrong with VID, no way to know why.

Well, updating to DS5 would probably be good, but takes take, so I’d like to postpone that for now :)
There’s some race in my code and I’m not sure updating will fix the issue.

What I’ve noticed is what GST documentation says about gst_element_change_state (which is where that another thread at): “this is racy if the state lock of the parent bin is not taken. The parent bin might’ve just checked the flag in another thread and as the next step proceed to change the child element’s state.”

I confirm, DS5.0.0 fixes that issue.