1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

Fix #1230, racing condition in source fetch or create. 3.0.110

This commit is contained in:
winlin 2020-01-28 21:35:06 +08:00
parent 5d365bade8
commit adf7ef4511
6 changed files with 24 additions and 4 deletions

View file

@ -1650,15 +1650,26 @@ SrsSourceManager* _srs_sources = new SrsSourceManager();
SrsSourceManager::SrsSourceManager()
{
lock = NULL;
}
SrsSourceManager::~SrsSourceManager()
{
srs_mutex_destroy(lock);
}
srs_error_t SrsSourceManager::fetch_or_create(SrsRequest* r, ISrsSourceHandler* h, SrsSource** pps)
{
srs_error_t err = srs_success;
// Lazy create lock, because ST is not ready in SrsSourceManager constructor.
if (!lock) {
lock = srs_mutex_new();
}
// Use lock to protect coroutine switch.
// @bug https://github.com/ossrs/srs/issues/1230
SrsLocker(lock);
SrsSource* source = NULL;
if ((source = fetch(r)) != NULL) {
@ -1676,6 +1687,7 @@ srs_error_t SrsSourceManager::fetch_or_create(SrsRequest* r, ISrsSourceHandler*
if ((err = source->initialize(r, h)) != srs_success) {
return srs_error_wrap(err, "init source %s", r->get_stream_url().c_str());
}
srs_usleep(10 * SRS_UTIME_SECONDS);
pool[stream_url] = source;