rtpmanager/rtsession: data race leading to critical warnings
This is a fix for a data race leading to:
GLib-CRITICAL: g_hash_table_foreach: assertion 'version == hash_table->version' failed
Identified sequence:
-
rtp_session_on_timeout
acquires the lock onsession
and proceeds with its processing. -
rtp_session_process_rtcp
is called (debug log : received RTCP packet) and attempts to acquire the lock onsession
, which is still held byrtp_session_on_timeout
. - as part of an hash table iterator,
rtp_session_on_timeout
transitively invokessource_caps
which releases the lock onsession
so as to callsession->callbacks.caps
. - Since
rtp_session_process_rtcp
was waiting for the lock to be released, it succeeds in acquiring it and proceeds withrtp_session_process_rr
which transitively callsg_hash_table_insert
viaadd_source
. - After
source_caps
re-acquires the lock and gives the control flow back tortp_session_on_timeout
, the hash table iterator is changed, resulting in the assertion failure.
This commits copies sess->ssrcs[sess->mask_idx]
and iterates on the copy so
the iterator is not affected by a concurrent change due to the lock being
released in the source_caps
callback.
Fixes: #2536 (closed)