GLib (gthread-posix.c): Unexpected error from C library during 'pthread_setspecific': Invalid argument. Aborting

Here the steps to reproduce the issue:

docker run -it -d --network host --runtime nvidia -v /tmp/.X11-unix:/tmp/.X11-unix -e DISPLAY=$DISPLAY --volume ${PWD}:/root/apps/ -w /root/apps/ nvcr.io/nvidia/deepstream:6.4-gc-triton-devel bash

Inside the docker container followed the steps from FAQ

wget https://github.com/GNOME/glib/archive/refs/tags/2.79.1.tar.gz
tar -xzvf 2.79.1.tar.gz
cd glib-2.79.1/
rm -r subprojects/gvdb
meson _build
ninja -C _build
ninja -C _build install

Post successful installation of the above library, built the sample deepstream-server

cd /opt/nvidia/deepstream/deepstream/sources/apps/sample_apps/deepstream-server
export CUDA_VER=12.2
make
./deepstream-server-app ./dsserver_config.yml

The program fails with the below logs

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.502: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/deepstream/libnvdsgst_udp.so': librivermax.so.1: cannot open shared object file: No such file or directory

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.511: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstmpeg2enc.so': libmpeg2encpp-2.1.so.0: cannot open shared object file: No such file or directory

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.517: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstmpg123.so': libmpg123.so.0: cannot open shared object file: No such file or directory

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.564: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstopenmpt.so': libmpg123.so.0: cannot open shared object file: No such file or directory

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.586: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstchromaprint.so': libavcodec.so.58: cannot open shared object file: No such file or directory

(gst-plugin-scanner:16979): GStreamer-WARNING **: 08:51:18.594: Failed to load plugin '/usr/lib/x86_64-linux-gnu/gstreamer-1.0/libgstmpeg2dec.so': libmpeg2.so.0: cannot open shared object file: No such file or directory
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_setspecific': Invalid argument.  Aborting.

This error occurs randomly in a few instances and sometimes the pipeline runs without any error.
With the help of gdb the error is arising from the gst_init call in the program.