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

fix: SIGKILL signal caused by synchronous waiting in device-orientation logic #337

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -212,51 +212,33 @@ - (void)testGrowingPageEvent {
.setAttributes(@{@"key" : @"value"});
[GrowingEventManager.sharedInstance postEventBuilder:builder];

// !!! 注意:这里有个隐藏的死锁问题 !!!
// 首次发送 GrowingPageEvent 时,-[GrowingDeviceInfo deviceOrientation] 中,有个子线程同步等待主线程的操作
// 如果此时主线程也在同步等待子线程,则会造成死锁,比如在主线程调用以下代码:
// [GrowingDispatchManager dispatchInGrowingThread:^{} waitUntilDone:YES];
// 因此,这里在子线程验证PageEvent
XCTestExpectation *expectation = [self expectationWithDescription:@"testGrowingPageEvent Test failed : timeout"];
dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSArray<GrowingBaseEvent *> *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage];
XCTAssertEqual(events.count, 1);

GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject;
XCTAssertEqualObjects(event.eventType, GrowingEventTypePage);
XCTAssertEqualObjects(event.pageName, @"path");
XCTAssertEqualObjects(event.orientation, orientation);
XCTAssertEqualObjects(event.title, @"title");
XCTAssertEqualObjects(event.referralPage, @"referralPage");
XCTAssertEqualObjects(event.attributes[@"key"], @"value");

NSDictionary *dic = event.toDictionary;
XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage);
XCTAssertEqualObjects(dic[@"path"], @"path");
XCTAssertEqualObjects(dic[@"orientation"], orientation);
XCTAssertEqualObjects(dic[@"title"], @"title");
XCTAssertEqualObjects(dic[@"referralPage"], @"referralPage");
XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value");

NSMutableDictionary *mDic = dic.mutableCopy;
if (dic[@"orientation"] == nil && orientation == nil) {
// 在无HostApplication的Logic Test时,orientation将为nil,这里手动赋值为PORTRAIT
mDic[@"orientation"] = @"PORTRAIT";
}
XCTAssertTrue([ManualTrackHelper pageEventCheck:mDic]);
XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:mDic]);

[expectation fulfill];
});
NSArray<GrowingBaseEvent *> *events = [MockEventQueue.sharedQueue eventsFor:GrowingEventTypePage];
XCTAssertEqual(events.count, 1);

[self waitForExpectationsWithTimeout:3.0f handler:nil];
GrowingPageEvent *event = (GrowingPageEvent *)events.firstObject;
XCTAssertEqualObjects(event.eventType, GrowingEventTypePage);
XCTAssertEqualObjects(event.pageName, @"path");
XCTAssertEqualObjects(event.orientation, orientation);
XCTAssertEqualObjects(event.title, @"title");
XCTAssertEqualObjects(event.referralPage, @"referralPage");
XCTAssertEqualObjects(event.attributes[@"key"], @"value");

NSDictionary *dic = event.toDictionary;
XCTAssertEqualObjects(dic[@"eventType"], GrowingEventTypePage);
XCTAssertEqualObjects(dic[@"path"], @"path");
XCTAssertEqualObjects(dic[@"orientation"], orientation);
XCTAssertEqualObjects(dic[@"title"], @"title");
XCTAssertEqualObjects(dic[@"referralPage"], @"referralPage");
XCTAssertEqualObjects(dic[@"attributes"][@"key"], @"value");
XCTAssertTrue([ManualTrackHelper pageEventCheck:dic]);
XCTAssertTrue([ManualTrackHelper contextOptionalPropertyCheck:dic]);
}

#pragma mark - Private Methods

- (NSString *)deviceOrientation {
// SDK配置pageEvent.orientation的逻辑
__block NSString *deviceOrientation = nil;
__block NSString *deviceOrientation = @"PORTRAIT";
dispatch_block_t block = ^{
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation != UIInterfaceOrientationUnknown) {
Expand Down
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
GrowingAnalytics: 0f45c3be51d1daaeabc98025586c448922c8ae72
GrowingAnalytics: 36c504c30f5ab374148cbcf7eb0e32cb85ceaeea
GrowingAnalytics-cdp: 08c85179967c06c36e7377731e2fc7aefc8c470f
GrowingAPM: 3c4de0384935b654e6798b95606f47883a99418b
GrowingToolsKit: 53160d19690da0b78e04a9242abde7af86442922
Expand All @@ -174,4 +174,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 8b74d64200d8437dbd5c21a406bd3513fc0eebd0

COCOAPODS: 1.15.2
COCOAPODS: 1.16.1
2 changes: 1 addition & 1 deletion GrowingAnalytics-cdp.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GrowingAnalytics-cdp'
s.version = '3.8.5'
s.version = '3.8.6'
s.summary = 'iOS SDK of GrowingIO.'
s.description = <<-DESC
GrowingAnalytics-cdp基于GrowingAnalytics,同样具备自动采集基本的用户行为事件,比如访问和行为数据等。
Expand Down
2 changes: 1 addition & 1 deletion GrowingAnalytics.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'GrowingAnalytics'
s.version = '3.8.5'
s.version = '3.8.6'
s.summary = 'iOS SDK of GrowingIO.'
s.description = <<-DESC
GrowingAnalytics具备自动采集基本的用户行为事件,比如访问和行为数据等。目前支持代码埋点、无埋点、可视化圈选、热图等功能。
Expand Down
8 changes: 3 additions & 5 deletions GrowingTrackerCore/GrowingRealTracker.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
#import "GrowingTrackerCore/Utils/GrowingDeviceInfo.h"
#import "GrowingULAppLifecycle.h"

NSString *const GrowingTrackerVersionName = @"3.8.5";
const int GrowingTrackerVersionCode = 30805;
NSString *const GrowingTrackerVersionName = @"3.8.6";
const int GrowingTrackerVersionCode = 30806;

@interface GrowingRealTracker ()

Expand All @@ -57,11 +57,9 @@ - (instancetype)initWithConfiguration:(GrowingTrackConfiguration *)configuration
_configuration = [configuration copyWithZone:nil];
_launchOptions = [launchOptions copy];
GrowingConfigurationManager.sharedInstance.trackConfiguration = self.configuration;
if (configuration.urlScheme.length > 0) {
[GrowingDeviceInfo configUrlScheme:configuration.urlScheme.copy];
}

[self loggerSetting];
[GrowingDeviceInfo setup];
[GrowingULAppLifecycle setup];
[GrowingSession startSession];
#if TARGET_OS_IOS
Expand Down
3 changes: 2 additions & 1 deletion GrowingTrackerCore/Utils/GrowingDeviceInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
@property (nonatomic, readonly, assign) CGFloat screenWidth;
@property (nonatomic, readonly, assign) CGFloat screenHeight;
@property (nonatomic, copy) NSString * (^encryptStringBlock)(NSString *string);
@property (nonatomic, readonly, assign) NSInteger timezoneOffset;

+ (instancetype)currentDeviceInfo;
+ (void)configUrlScheme:(NSString *)urlScheme;
+ (void)setup;

@end
Loading
Loading