Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS退到后台执行background task,当超过15s执行mars::stn::Reset()有一定概率会crash #358

Closed
zhgw01 opened this issue Jan 8, 2018 · 4 comments

Comments

@zhgw01
Copy link

zhgw01 commented Jan 8, 2018

由于业务的需求,需要在退到后台超过15s后端口mars的连接。 所以加了一点示例中的代码。结果加了这端代码后,mars相关的crash就开始上升

看了crash log1中的代码, GetAppFilePath实现非常简单。 现有mars框架支持iOS后台运行吗?还是因为我使用不正确?

crash log 1

0  0x100cb68cc mars::app::GetAppFilePath() (app_logic.cc:156)
1  0x100c8dda8 mars::stn::SimpleIPPortSort::SimpleIPPortSort() (string:3803)
2  0x100c8dda8 mars::stn::SimpleIPPortSort::SimpleIPPortSort() (string:3803)
3  0x100c76bfc mars::stn::NetSource::NetSource(ActiveLogic&) (xlogger.h:237)
4  0x100c6a3c0 mars::stn::NetCore::NetCore() (shared_ptr.hpp:762)
5  0x100c95458 mars::stn::NetCore::Singleton::Instance() (shared_ptr.hpp:371)
6  0x100c9e604 mars::stn::$_5::__invoke() (shared_ptr.hpp:762)

crash log 2

0  0x100c25ff0 mars_boost::signals2::detail::signal0_impl<void, mars_boost::signals2::optional_last_value<void>, int, std::__1::less<int>, mars_boost::function<void ()>, mars_boost::function<void (mars_boost::signals2::connection const&)>, mars_boost::signals2::mutex>::operator()() (sp_counted_base_clang.hpp:132)
1  0x100c25fe4 mars_boost::signals2::detail::signal0_impl<void, mars_boost::signals2::optional_last_value<void>, int, std::__1::less<int>, mars_boost::function<void ()>, mars_boost::function<void (mars_boost::signals2::connection const&)>, mars_boost::signals2::mutex>::operator()() (shared_count.hpp:525)
2  0x100c25448 mars::stn::NetCore::Singleton::Instance() (net_core.h:62)
3  0x100c2e604 mars::stn::$_5::__invoke() (shared_ptr.hpp:762)

示例代码

- (void)startBackgroundTask {
    if (self.bgTask) {
        [self.bgTask end];
    }
    
    BackgroundTask *bgTask = [BackgroundTask start];
    self.bgTask = bgTask;
    
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC), self.serialQueue, ^{
        if (bgTask == self.bgTask) {
            
            mars::stn::Reset();

            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), self.serialQueue, ^{
                [self endBackgroundTask];
            });
        }
    });
}

- (void)endBackgroundTask {
    if (self.bgTask) {
        [self.bgTask end];
        
    }
    
    self.bgTask = nil;
}

版本

Xcode version: 9.0

iOS/OSX version: 8,9,10,11都有可能出现

@zhgw01 zhgw01 changed the title iOS退到后台执行background task,当超过15s执行mars::stn::Reset()有一定规律会crash iOS退到后台执行background task,当超过15s执行mars::stn::Reset()有一定概率会crash Jan 8, 2018
@garryyan
Copy link
Collaborator

garryyan commented Jan 8, 2018

切到后台你应用层是否申请了后台短时间的运行权限

@zhgw01
Copy link
Author

zhgw01 commented Jan 9, 2018

申请了,申请的background mode为

  1. Background fetch
  2. Remote notification

其它有涉及到后台运行的,比如清缓存之类的,并没有问题, 但请缓存没有特别设置时间。

mars这边会特别设置进入后台15s后才会去reset,不知道跟这个是否有关联。另外这个crash也不是必现。

所以在这边问下

@garryyan
Copy link
Collaborator

garryyan commented Jan 9, 2018

连着xcode 看下堆栈吧。 这里crash信息看不出来什么问题,我们这边也没遇到过这种问题。 还有 为什么要reset。reset会断开连接之后再次建立连接的

@zhgw01
Copy link
Author

zhgw01 commented Jan 9, 2018

谢谢,我看看本地能不能复现出来。
reset是为了断开连接,这样服务器端能明确知道客户端断开了,推送消息计数可以准确点

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants