Skip to content

Commit 8f09c41

Browse files
authored
WebRTC: Fix race condition in RTC nack timer callbacks. v7.0.79 (#4474)
See [WebRTC: Fix race condition in RTC publish timer callbacks.](421ab6c) v7.0.76 (#4470)
1 parent 57e1622 commit 8f09c41

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

trunk/doc/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The changelog for SRS.
77
<a name="v7-changes"></a>
88

99
## SRS 7.0 Changelog
10+
* v7.0, 2025-09-05, Merge [#4474](https://github.com/ossrs/srs/pull/4474): WebRTC: Fix race condition in RTC nack timer callbacks. v7.0.79 (#4474)
1011
* v7.0, 2025-09-04, Merge [#4467](https://github.com/ossrs/srs/pull/4467): WebRTC: Fix NACK recovered packets not being added to receive queue. v7.0.78 (#4467)
1112
* v7.0, 2025-09-03, Merge [#4469](https://github.com/ossrs/srs/pull/4469): Upgrade HTTP parser from http-parser to llhttp. v7.0.77 (#4469)
1213
* v7.0, 2025-09-03, Merge [#4470](https://github.com/ossrs/srs/pull/4470): RTX: Fix race condition for timer. v7.0.76 (#4470)

trunk/src/app/srs_app_rtc_conn.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1745,18 +1745,29 @@ void SrsRtcPublishStream::update_send_report_time(uint32_t ssrc, const SrsNtp &n
17451745

17461746
SrsRtcConnectionNackTimer::SrsRtcConnectionNackTimer(SrsRtcConnection *p) : p_(p)
17471747
{
1748+
lock_ = srs_mutex_new();
17481749
_srs_shared_timer->timer20ms()->subscribe(this);
17491750
}
17501751

17511752
SrsRtcConnectionNackTimer::~SrsRtcConnectionNackTimer()
17521753
{
1753-
_srs_shared_timer->timer20ms()->unsubscribe(this);
1754+
if (true) {
1755+
SrsLocker(lock_);
1756+
_srs_shared_timer->timer20ms()->unsubscribe(this);
1757+
}
1758+
srs_mutex_destroy(lock_);
17541759
}
17551760

17561761
srs_error_t SrsRtcConnectionNackTimer::on_timer(srs_utime_t interval)
17571762
{
17581763
srs_error_t err = srs_success;
17591764

1765+
// This is a very heavy function, and it may potentially cause a coroutine switch.
1766+
// Therefore, during this function, the 'this' pointer might become invalid because
1767+
// the object could be freed by another thread. As a result, we must lock the object
1768+
// to prevent it from being freed.
1769+
SrsLocker(lock_);
1770+
17601771
if (!p_->nack_enabled_) {
17611772
return err;
17621773
}

trunk/src/app/srs_app_rtc_conn.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ class SrsRtcConnectionNackTimer : public ISrsFastTimer
454454
{
455455
private:
456456
SrsRtcConnection *p_;
457+
srs_mutex_t lock_;
457458

458459
public:
459460
SrsRtcConnectionNackTimer(SrsRtcConnection *p);

trunk/src/core/srs_core_version7.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99

1010
#define VERSION_MAJOR 7
1111
#define VERSION_MINOR 0
12-
#define VERSION_REVISION 78
12+
#define VERSION_REVISION 79
1313

1414
#endif

0 commit comments

Comments
 (0)