Commit 50fa6715 by xiongziliang

修复析构中调用getOwnerPoller抛异常导致崩溃的bug:#2117

parent 9fd5152a
ZLToolKit @ 25ba684a
Subproject commit 617b6b1db23f13e2592b29204b84b1b9dbbf81c0
Subproject commit 25ba684a49142cc59e43719c98112031e1ec4bda
......@@ -344,7 +344,8 @@ Value makeMediaSourceJson(MediaSource &media){
}
//getLossRate有线程安全问题;使用getMediaInfo接口才能获取丢包率;getMediaList接口将忽略丢包率
auto current_thread = media.getOwnerPoller()->isCurrentThread();
auto current_thread = false;
try { current_thread = media.getOwnerPoller()->isCurrentThread();} catch (...) {}
float last_loss = -1;
for(auto &track : media.getTracks(false)){
Value obj;
......
......@@ -124,7 +124,6 @@ MediaSource::MediaSource(const string &schema, const string &vhost, const string
_app = app;
_stream_id = stream_id;
_create_stamp = time(NULL);
_default_poller = EventPollerPool::Instance().getPoller();
}
MediaSource::~MediaSource() {
......@@ -289,23 +288,29 @@ toolkit::EventPoller::Ptr MediaSource::getOwnerPoller() {
if (listener) {
return listener->getOwnerPoller(*this);
}
WarnL << toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed, now return default poller: " + getUrl();
return _default_poller;
throw std::runtime_error(toolkit::demangle(typeid(*this).name()) + "::getOwnerPoller failed: " + getUrl());
}
void MediaSource::onReaderChanged(int size) {
weak_ptr<MediaSource> weak_self = shared_from_this();
auto listener = _listener.lock();
if (!listener) {
return;
try {
weak_ptr<MediaSource> weak_self = shared_from_this();
getOwnerPoller()->async([weak_self, size]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
auto listener = strong_self->_listener.lock();
if (listener) {
listener->onReaderChanged(*strong_self, size);
}
});
} catch (MediaSourceEvent::NotImplemented &ex) {
// 未实现接口,应该打印异常
WarnL << ex.what();
} catch (...) {
// getOwnerPoller()接口抛异常机制应该只对外不对内
// 所以listener已经销毁导致获取归属线程失败的异常直接忽略
}
getOwnerPoller()->async([weak_self, size, listener]() {
auto strong_self = weak_self.lock();
if (!strong_self) {
return;
}
listener->onReaderChanged(*strong_self, size);
});
}
bool MediaSource::setupRecord(Recorder::type type, bool start, const string &custom_path, size_t max_second){
......
......@@ -406,7 +406,6 @@ private:
std::string _app;
std::string _stream_id;
std::weak_ptr<MediaSourceEvent> _listener;
toolkit::EventPoller::Ptr _default_poller;
// 对象个数统计
toolkit::ObjectStatistic<MediaSource> _statistic;
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论