Session not In Place panic when reading WebRTC stats

Hello!

I’m developing a WebRTC Application using Rust + GStreamer. We are interesed in logging the stats form the webrtcsink. However, when starting a session, the code panics. Seems strange to me, since I check whether a session in in place (and it is!). If I sleep for 5 seconds after the session is started and then start logging, the panic does not happen.

Any help is much appreciated!

The code:

async fn log_webrtc_stats(webrtcsink: gst::glib::WeakRef<gst::Element>) {
        // tokio::time::sleep(std::time::Duration::from_secs(5)).await;
        let mut interval = tokio::time::interval(std::time::Duration::from_millis(100));
        loop {
            interval.tick().await;
            if let Some(webrtcsink_upgraded) = webrtcsink.upgrade() {
                let mut ret: &[&(dyn ToValue)] = &[];
                let x = webrtcsink_upgraded
                    .emit_by_name::<gst::glib::collections::StrV>("get-sessions", ret);
                info!("{:?}", x);
                let stats = webrtcsink_upgraded.property::<gst::Structure>("stats");
                let stats = serialize_value(&stats.to_value());
                if let Ok(stats_string) = serde_json::to_string(&stats) {
                    if stats_string != "{}" {
                        let _span = info_span!("analytics_data_webrtc_stats").entered();
                        info!(name: "analytics_data_webrtc_stats", webrtc_stats = stats_string);
                    } else {
                        return;
                    }
                }
            } else {
                break;
            }
        }
    }

My output:

unit-1  |   2024-06-13T14:24:50.749542Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:50.751921Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:50.849462Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:50.849727Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:50.950085Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:50.950309Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:51.049790Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:51.050051Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:51.149534Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:51.149765Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:51.250558Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:51.250791Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:51.350292Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:51.350526Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  |   2024-06-13T14:24:51.449974Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |   2024-06-13T14:24:51.450198Z  INFO unit::video_stream: webrtc_stats: "{\"2e0c0c38-e231-430d-8289-1c07c3b67f96\":{\"consumer-stats\":{\"video-encoders\":[]}}}"
unit-1  |     at unit/src/video_stream.rs:74
unit-1  |     in unit::video_stream::analytics_data_webrtc_stats
unit-1  | 
unit-1  | thread 'tokio-runtime-worker' panicked at /root/.cargo/git/checkouts/gst-plugins-rs-2155d1592d6bb9f7/5b01e43/net/webrtc/src/webrtcsink/imp.rs:319:18:
unit-1  | Session is not In Place
unit-1  | stack backtrace:
unit-1  |   2024-06-13T14:24:51.549364Z  INFO unit::video_stream: ["2e0c0c38-e231-430d-8289-1c07c3b67f96"]
unit-1  |     at unit/src/video_stream.rs:68
unit-1  | 
unit-1  |    0:       0x557477db58 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haee13570c31cb77b
unit-1  |    1:       0x55747a58e8 - core::fmt::write::he0b40f3f74e7e87c
unit-1  |    2:       0x557477a500 - std::io::Write::write_fmt::hc8024efb884f388c
unit-1  |    3:       0x557477d9a4 - std::sys_common::backtrace::print::hf1431a2be8ae8207
unit-1  |    4:       0x557477efec - std::panicking::default_hook::{{closure}}::ha26cf0d89fc27676
unit-1  |    5:       0x557477eca0 - std::panicking::default_hook::hddcfc2aac016eb46
unit-1  |    6:       0x557477f3f8 - std::panicking::rust_panic_with_hook::hbd9f5866892982cc
unit-1  |    7:       0x557477f27c - std::panicking::begin_panic_handler::{{closure}}::hf930a65f0587fc68
unit-1  |    8:       0x557477e01c - std::sys_common::backtrace::__rust_end_short_backtrace::h8aeef1aadd5204df
unit-1  |    9:       0x557477f040 - rust_begin_unwind
unit-1  |   10:       0x5573cbce14 - core::panicking::panic_fmt::h3c23aa0af13818a0
unit-1  |   11:       0x5573e11a20 - hashbrown::raw::RawIterRange<T>::fold_impl::h19bf62805cd749ec
unit-1  |   12:       0x5573eef898 - gstrswebrtc::webrtcsink::imp::BaseWebRTCSink::gather_stats::he13a9ed5f6104fa9
unit-1  |   13:       0x5573ef1fa8 - <gstrswebrtc::webrtcsink::imp::BaseWebRTCSink as glib::subclass::object::ObjectImpl>::property::h2c5c218f70206955
unit-1  |   14:       0x5573e0af94 - glib::subclass::object::property::h5a5a09593b3477ea
unit-1  |   15:       0x7faf3490d8 - g_object_get_property
unit-1  |   16:       0x5573ce8b30 - <T as glib::object::ObjectExt>::property_value::hab8a4f0a3e24c474
unit-1  |   17:       0x5573ce8d18 - <T as glib::object::ObjectExt>::property::hdb954003f3c4503c
unit-1  |   18:       0x5573cc46d8 - unit::video_stream::VideoStreamInterface::log_webrtc_stats::{{closure}}::h16b6daf2031b9587
unit-1  |   19:       0x5573cc0924 - tokio::runtime::task::core::Core<T,S>::poll::h3887173fec753200
unit-1  |   20:       0x5573cd930c - tokio::runtime::task::harness::Harness<T,S>::poll::hb0cdf64bbdf3aa90
unit-1  |   21:       0x557473c9d8 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h6bbc1fa9817619f2
unit-1  |   22:       0x557473c174 - tokio::runtime::scheduler::multi_thread::worker::Context::run::h2124eb4dde52f3e5
unit-1  |   23:       0x557472c550 - tokio::runtime::context::set_scheduler::h665953ef0e30b1c8
unit-1  |   24:       0x557472f5b0 - tokio::runtime::context::runtime::enter_runtime::h6e0e5910f281b092
unit-1  |   25:       0x557473b640 - tokio::runtime::scheduler::multi_thread::worker::run::h6eea1c678323b546
unit-1  |   26:       0x557473480c - tokio::runtime::task::core::Core<T,S>::poll::h9da0b3e769e1c7e8
unit-1  |   27:       0x557471a288 - tokio::runtime::task::harness::Harness<T,S>::poll::h3f9ae32bac248309
unit-1  |   28:       0x5574722ea4 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb0042c4c16982a5a
unit-1  |   29:       0x557472b688 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h42813391c6d0b316
unit-1  |   30:       0x5574783420 - std::sys::pal::unix::thread::Thread::new::thread_start::h05189fd97c8bce01
unit-1  |   31:       0x7fae6bd5c8 - <unknown>
unit-1  |   32:       0x7fae725edc - <unknown>
unit-1  |   33:                0x0 - <unknown>
unit-1  | thread '<unnamed>' panicked at /root/.cargo/git/checkouts/gst-plugins-rs-2155d1592d6bb9f7/5b01e43/net/webrtc/src/webrtcsink/imp.rs:3531:47:
unit-1  | called `Result::unwrap()` on an `Err` value: PoisonError { .. }
unit-1  | stack backtrace:
unit-1  |    0:       0x557477db58 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haee13570c31cb77b
unit-1  |    1:       0x55747a58e8 - core::fmt::write::he0b40f3f74e7e87c
unit-1  |    2:       0x557477a500 - std::io::Write::write_fmt::hc8024efb884f388c
unit-1  |    3:       0x557477d9a4 - std::sys_common::backtrace::print::hf1431a2be8ae8207
unit-1  |    4:       0x557477efec - std::panicking::default_hook::{{closure}}::ha26cf0d89fc27676
unit-1  |    5:       0x557477eca0 - std::panicking::default_hook::hddcfc2aac016eb46
unit-1  |    6:       0x557477f3f8 - std::panicking::rust_panic_with_hook::hbd9f5866892982cc
unit-1  |    7:       0x557477f2a8 - std::panicking::begin_panic_handler::{{closure}}::hf930a65f0587fc68
unit-1  |    8:       0x557477e01c - std::sys_common::backtrace::__rust_end_short_backtrace::h8aeef1aadd5204df
unit-1  |    9:       0x557477f040 - rust_begin_unwind
unit-1  |   10:       0x5573cbce14 - core::panicking::panic_fmt::h3c23aa0af13818a0
unit-1  |   11:       0x5573cbd168 - core::result::unwrap_failed::h96aa0d56e71b0bb4
unit-1  |   12:       0x5573eeff50 - gstrswebrtc::webrtcsink::imp::BaseWebRTCSink::chain::h92e9b950d3b5d38d
unit-1  |   13:       0x5573ed7c48 - gstreamer::subclass::element::ElementImplExt::catch_panic_pad_function::hda13d30546e07093
unit-1  |   14:       0x5573f06650 - gstreamer::pad::trampoline_chain_function::he1e4550ad5176e62
unit-1  |   15:       0x7faf434910 - <unknown>
unit-1  |   16:       0x7faf437390 - <unknown>
unit-1  |   17:       0x7faf43fcbc - gst_pad_push
unit-1  |   18:       0x7faf14d7d4 - <unknown>
unit-1  |   19:       0x7faf434910 - <unknown>
unit-1  |   20:       0x7faf437390 - <unknown>
unit-1  |   21:       0x7faf43fcbc - gst_pad_push
unit-1  |   22:       0x7fa7f27b50 - <unknown>
unit-1  |   23:       0x7faf14de74 - <unknown>
unit-1  |   24:       0x7faf14d6c4 - <unknown>
unit-1  |   25:       0x7faf434910 - <unknown>
unit-1  |   26:       0x7faf437390 - <unknown>
unit-1  |   27:       0x7faf43fcbc - gst_pad_push
unit-1  |   28:       0x7fa7ef9f58 - <unknown>
unit-1  |   29:       0x7fa7efc8b0 - <unknown>
unit-1  |   30:       0x7faf434910 - <unknown>
unit-1  |   31:       0x7faf437390 - <unknown>
unit-1  |   32:       0x7faf43fcbc - gst_pad_push
unit-1  |   33:       0x7faf14d7d4 - <unknown>
unit-1  |   34:       0x7faf434910 - <unknown>
unit-1  |   35:       0x7faf437390 - <unknown>
unit-1  |   36:       0x7faf43fcbc - gst_pad_push
unit-1  |   37:       0x7faeffcae8 - <unknown>
unit-1  |   38:       0x7faf002438 - gst_video_decoder_finish_frame
unit-1  |   39:       0x7fac0a8b7c - <unknown>
unit-1  |   40:       0x7faf0051cc - <unknown>
unit-1  |   41:       0x7faf0056c4 - <unknown>
unit-1  |   42:       0x7faf007eb8 - <unknown>
unit-1  |   43:       0x7faf434910 - <unknown>
unit-1  |   44:       0x7faf437390 - <unknown>
unit-1  |   45:       0x7faf43fcbc - gst_pad_push
unit-1  |   46:       0x7faf12ebf4 - gst_base_parse_push_frame
unit-1  |   47:       0x7fac0c3228 - <unknown>
unit-1  |   48:       0x7fac0c4a04 - <unknown>
unit-1  |   49:       0x7faf129da8 - <unknown>
unit-1  |   50:       0x7faf12f47c - <unknown>
unit-1  |   51:       0x7faf434910 - <unknown>
unit-1  |   52:       0x7faf437390 - <unknown>
unit-1  |   53:       0x7faf43fcbc - gst_pad_push
unit-1  |   54:       0x7faf14d7d4 - <unknown>
unit-1  |   55:       0x7faf434910 - <unknown>
unit-1  |   56:       0x7faf437390 - <unknown>
unit-1  |   57:       0x7faf43fcbc - gst_pad_push
unit-1  |   58:       0x7faf146688 - <unknown>
unit-1  |   59:       0x7faf474d6c - <unknown>
unit-1  |   60:       0x7faf257668 - <unknown>
unit-1  |   61:       0x7faf254990 - <unknown>
unit-1  |   62:       0x7fae6bd5c8 - <unknown>
unit-1  |   63:       0x7fae725edc - <unknown>
unit-1  |   64:                0x0 - <unknown>
unit-1  | thread 'tokio-runtime-worker' panicked at /root/.cargo/git/checkouts/gst-plugins-rs-2155d1592d6bb9f7/5b01e43/net/webrtc/src/webrtcsink/imp.rs:3055:43:
unit-1  | called `Result::unwrap()` on an `Err` value: PoisonError { .. }
unit-1  | stack backtrace:
unit-1  |    0:       0x557477db58 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haee13570c31cb77b
unit-1  |    1:       0x55747a58e8 - core::fmt::write::he0b40f3f74e7e87c
unit-1  |    2:       0x557477a500 - std::io::Write::write_fmt::hc8024efb884f388c
unit-1  |    3:       0x557477d9a4 - std::sys_common::backtrace::print::hf1431a2be8ae8207
unit-1  |    4:       0x557477efec - std::panicking::default_hook::{{closure}}::ha26cf0d89fc27676
unit-1  |    5:       0x557477eca0 - std::panicking::default_hook::hddcfc2aac016eb46
unit-1  |    6:       0x557477f3f8 - std::panicking::rust_panic_with_hook::hbd9f5866892982cc
unit-1  |    7:       0x557477f2a8 - std::panicking::begin_panic_handler::{{closure}}::hf930a65f0587fc68
unit-1  |    8:       0x557477e01c - std::sys_common::backtrace::__rust_end_short_backtrace::h8aeef1aadd5204df
unit-1  |    9:       0x557477f040 - rust_begin_unwind
unit-1  |   10:       0x5573cbce14 - core::panicking::panic_fmt::h3c23aa0af13818a0
unit-1  |   11:       0x5573cbd168 - core::result::unwrap_failed::h96aa0d56e71b0bb4
unit-1  |   12:       0x5573eee6f0 - gstrswebrtc::webrtcsink::imp::BaseWebRTCSink::handle_ice::hf41860524b2c641c
unit-1  |   13:       0x5573f7ae2c - glib::closure::Closure::new_unsafe::marshal::h639e8b2a5bdcc827
unit-1  |   14:       0x7faf3348e8 - g_closure_invoke
unit-1  |   15:       0x7faf364104 - <unknown>
unit-1  |   16:       0x5573f20f0c - <T as glib::object::ObjectExt>::emit_by_name::hd30fac970e847e81
unit-1  |   17:       0x5573f91ba0 - gstrswebrtc::signaller::imp::Signaller::handle_message::hee97ce67ca6bacd1
unit-1  |   18:       0x5574010ed8 - gstrswebrtc::signaller::imp::Signaller::connect::{{closure}}::{{closure}}::heb9fbdd2ad8fc106
unit-1  |   19:       0x5573ff2e08 - tokio::runtime::task::core::Core<T,S>::poll::hae96505593be953e
unit-1  |   20:       0x5573f58e54 - tokio::runtime::task::harness::Harness<T,S>::poll::h94cb76c453fe3e49
unit-1  |   21:       0x557473c9d8 - tokio::runtime::scheduler::multi_thread::worker::Context::run_task::h6bbc1fa9817619f2
unit-1  |   22:       0x557473c174 - tokio::runtime::scheduler::multi_thread::worker::Context::run::h2124eb4dde52f3e5
unit-1  |   23:       0x557472c550 - tokio::runtime::context::set_scheduler::h665953ef0e30b1c8
unit-1  |   24:       0x557472f5b0 - tokio::runtime::context::runtime::enter_runtime::h6e0e5910f281b092
unit-1  |   25:       0x557473b640 - tokio::runtime::scheduler::multi_thread::worker::run::h6eea1c678323b546
unit-1  |   26:       0x557473480c - tokio::runtime::task::core::Core<T,S>::poll::h9da0b3e769e1c7e8
unit-1  |   27:       0x557471a288 - tokio::runtime::task::harness::Harness<T,S>::poll::h3f9ae32bac248309
unit-1  |   28:       0x5574722ea4 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb0042c4c16982a5a
unit-1  |   29:       0x557472b688 - core::ops::function::FnOnce::call_once{{vtable.shim}}::h42813391c6d0b316
unit-1  |   30:       0x5574783420 - std::sys::pal::unix::thread::Thread::new::thread_start::h05189fd97c8bce01
unit-1  |   31:       0x7fae6bd5c8 - <unknown>
unit-1  |   32:       0x7fae725edc - <unknown>
unit-1  |   33:                0x0 - <unknown>
unit-1  | thread '<unnamed>' panicked at /root/.cargo/git/checkouts/gst-plugins-rs-2155d1592d6bb9f7/5b01e43/net/webrtc/src/webrtcsink/imp.rs:2992:47:
unit-1  | called `Result::unwrap()` on an `Err` value: PoisonError { .. }
unit-1  | stack backtrace:
unit-1  |    0:       0x557477db58 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::haee13570c31cb77b
unit-1  |    1:       0x55747a58e8 - core::fmt::write::he0b40f3f74e7e87c
unit-1  |    2:       0x557477a500 - std::io::Write::write_fmt::hc8024efb884f388c
unit-1  |    3:       0x557477d9a4 - std::sys_common::backtrace::print::hf1431a2be8ae8207
unit-1  |    4:       0x557477efec - std::panicking::default_hook::{{closure}}::ha26cf0d89fc27676
unit-1  |    5:       0x557477eca0 - std::panicking::default_hook::hddcfc2aac016eb46
unit-1  |    6:       0x557477f3f8 - std::panicking::rust_panic_with_hook::hbd9f5866892982cc
unit-1  |    7:       0x557477f2a8 - std::panicking::begin_panic_handler::{{closure}}::hf930a65f0587fc68
unit-1  |    8:       0x557477e01c - std::sys_common::backtrace::__rust_end_short_backtrace::h8aeef1aadd5204df
unit-1  |    9:       0x557477f040 - rust_begin_unwind
unit-1  |   10:       0x5573cbce14 - core::panicking::panic_fmt::h3c23aa0af13818a0
unit-1  |   11:       0x5573cbd168 - core::result::unwrap_failed::h96aa0d56e71b0bb4
unit-1  |   12:       0x5573eed7b8 - gstrswebrtc::webrtcsink::imp::BaseWebRTCSink::on_remote_description_set::hc261ffa741d863b3
unit-1  |   13:       0x5573d72454 - gstreamer::promise::Promise::with_change_func::trampoline::h78dc7d49aae534d0
unit-1  |   14:       0x7fa5e5e8d0 - <unknown>
unit-1  |   15:       0x7faf22595c - g_main_context_dispatch
unit-1  |   16:       0x7faf27aebc - <unknown>
unit-1  |   17:       0x7faf225024 - g_main_loop_run
unit-1  |   18:       0x7fa5e61470 - <unknown>
unit-1  |   19:       0x7faf254990 - <unknown>
unit-1  |   20:       0x7fae6bd5c8 - <unknown>
unit-1  |   21:       0x7fae725edc - <unknown>
unit-1  |   22:                0x0 - <unknown>
unit-1  | fatal runtime error: failed to initiate panic, error 1813276832
unit-1 exited with code 133