Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Monitor "Too many timers" error. And remove invalidate timers a…
Browse files Browse the repository at this point in the history
…utomatically. (#2352)
  • Loading branch information
wqyfavor authored and jianhan-he committed Apr 23, 2019
1 parent 674f4b5 commit 5805330
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
4 changes: 3 additions & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKError.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ typedef NS_ENUM(int, WXSDKErrCode)
WX_KEY_EXCEPTION_ABILITY_DOWN_ = -9603,

WX_KEY_EXCEPTION_EMPTY_SCREEN_JS = -9700,
WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE = -9701
WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE = -9701,

WX_KEY_EXCEPTION_TOO_MANY_TIMERS = -9800,
};

typedef NS_ENUM (NSInteger,WXSDKErrorType)
Expand Down
4 changes: 3 additions & 1 deletion ios/sdk/WeexSDK/Sources/Engine/WXSDKError.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ +(NSDictionary *) getMap
@(WX_ERR_JSFRAMEWORK_START):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_KEY_EXCEPTION_ABILITY_DOWN_):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)},
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_JS):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_JS)},
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_NATIVE)}
@(WX_KEY_EXCEPTION_EMPTY_SCREEN_NATIVE):@{ERROR_TYPE:@(WX_RENDER_ERROR),ERROR_GROUP:@(WX_NATIVE)},

@(WX_KEY_EXCEPTION_TOO_MANY_TIMERS):@{ERROR_TYPE:@(WX_NATIVE_ERROR),ERROR_GROUP:@(WX_NATIVE)}
};
});
return codeMap;
Expand Down
20 changes: 20 additions & 0 deletions ios/sdk/WeexSDK/Sources/Module/WXTimerModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#import "WXAssert.h"
#import "WXMonitor.h"
#import "WXSDKInstance_performance.h"
#import "WXSDKError.h"
#import "WXExceptionUtils.h"

@interface WXTimerTarget : NSObject

Expand Down Expand Up @@ -75,6 +77,7 @@ + (void) checkExcuteInBack:(NSString*) instanceId

@implementation WXTimerModule
{
BOOL _tooManyTimersReported;
NSMutableDictionary *_timers;
}

Expand Down Expand Up @@ -164,6 +167,23 @@ - (void)createTimerWithCallback:(NSString *)callbackID time:(NSTimeInterval)mill

if (!_timers[callbackID]) {
_timers[callbackID] = timer;

if ([_timers count] > 30) {
if (!_tooManyTimersReported) {
[WXExceptionUtils commitCriticalExceptionRT:self.weexInstance.instanceId errCode:[NSString stringWithFormat:@"%d", WX_KEY_EXCEPTION_TOO_MANY_TIMERS] function:@"" exception:@"Too many timers." extParams:nil];
_tooManyTimersReported = YES;
}

// remove invalid timers
NSMutableArray* invalidTimerIds = [[NSMutableArray alloc] init];
for (NSString *cbId in _timers) {
NSTimer *timer = _timers[cbId];
if (![timer isValid]) {
[invalidTimerIds addObject:cbId];
}
}
[_timers removeObjectsForKeys:invalidTimerIds];
}
}
}

Expand Down
1 change: 1 addition & 0 deletions ios/sdk/WeexSDK/Sources/Monitor/WXExceptionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
+ (void)commitCriticalExceptionRT:(NSString *)instanceId errCode:(NSString *)errCode function:(NSString *)function exception:(NSString *)exception extParams:(NSDictionary *)extParams;

+ (void)commitCriticalExceptionRT:(WXJSExceptionInfo*)jsExceptionInfo;

@end

4 changes: 2 additions & 2 deletions ios/sdk/WeexSDK/Sources/Utility/WXVersion.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#import "WXVersion.h"
#import "WXDefine.h"

static const char* WeexSDKBuildTime = "2019-04-16 13:26:54 UTC";
static const unsigned long WeexSDKBuildTimestamp = 1555421214;
static const char* WeexSDKBuildTime = "2019-04-23 06:34:41 UTC";
static const unsigned long WeexSDKBuildTimestamp = 1556001281;

NSString* GetWeexSDKVersion(void)
{
Expand Down

0 comments on commit 5805330

Please sign in to comment.