Skip to content

Commit 9e13e61

Browse files
Fix deadlock initializing sharedTemplates (#205)
https://leanplum.atlassian.net/browse/E2-1492 sharedTemplates was using an anti-singleton-anti-pattern. It was a dependency in its own initialization path.
1 parent a2e738f commit 9e13e61

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

Example/Tests/Classes/LPMessageTemplatesClassTest.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ - (void)test_dismiss_image
8282
XCTAssertNotNil(image);
8383
}
8484

85+
-(void)test_shared_templates_creation
86+
{
87+
// Previously, this was causing a deadlock.
88+
[LPMessageTemplatesClass sharedTemplates];
89+
}
90+
8591
- (void)test_popup_setup
8692
{
8793
// This stub have to be removed when start command is successfully executed.

Leanplum-SDK/Classes/Internal/LPInternalState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@property(assign, nonatomic) NSUncaughtExceptionHandler *customExceptionHandler;
2121
@property(strong, nonatomic) LPRegisterDevice *registration;
2222
@property(assign, nonatomic) BOOL calledStart, hasStarted, hasStartedAndRegisteredAsDeveloper,
23-
startSuccessful, issuedStart, initializedMessageTemplates, stripViewControllerFromState;
23+
startSuccessful, issuedStart, stripViewControllerFromState;
2424
@property(strong, nonatomic) LPActionManager *actionManager;
2525
@property(strong, nonatomic) NSString *deviceId;
2626
@property(strong, nonatomic) NSString *appVersion;

Leanplum-SDK/Classes/Internal/LPInternalState.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ - (id)init {
3939
_hasStarted = NO;
4040
_hasStartedAndRegisteredAsDeveloper = NO;
4141
_startSuccessful = NO;
42-
_initializedMessageTemplates = NO;
4342
_actionManager = nil;
4443
_deviceId = nil;
4544
_userAttributeChanges = [NSMutableArray array];

Leanplum-SDK/Classes/Internal/Leanplum.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,6 @@ + (void)startWithUserId:(NSString *)userId
723723
[self throwError:@"Already called start."];
724724
}
725725

726-
state.initializedMessageTemplates = YES;
727726
[LPMessageTemplatesClass sharedTemplates];
728727
attributes = [self validateAttributes:attributes named:@"userAttributes" allowLists:YES];
729728
if (attributes != nil) {
@@ -1548,10 +1547,6 @@ + (void)defineAction:(NSString *)name ofKind:(LeanplumActionKind)kind withArgume
15481547
}
15491548

15501549
LP_TRY
1551-
if (![LPInternalState sharedState].initializedMessageTemplates) {
1552-
[LPInternalState sharedState].initializedMessageTemplates = YES;
1553-
[LPMessageTemplatesClass sharedTemplates];
1554-
}
15551550
[[LPInternalState sharedState].actionBlocks removeObjectForKey:name];
15561551
[[LPVarCache sharedCache] registerActionDefinition:name ofKind:kind withArguments:args andOptions:options];
15571552
if (responder) {

0 commit comments

Comments
 (0)