Skip to content

Commit

Permalink
fix(Core): Fixing concurrency issues in AWSSynchronizedMutableDiction…
Browse files Browse the repository at this point in the history
…ary (#5413)

fix(IoT): Fixing random crash when a connection is attempted just after disconnecting
  • Loading branch information
sebaland authored Jul 31, 2024
1 parent 4b53d60 commit 21daae9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
12 changes: 6 additions & 6 deletions AWSCore/Utility/AWSSynchronizedMutableDictionary.m
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ - (id)objectForKey:(id)aKey {
}

- (void)setObject:(id)anObject forKey:(id)aKey {
dispatch_barrier_sync(self.dispatchQueue, ^{
dispatch_barrier_async(self.dispatchQueue, ^{
[self.dictionary setObject:anObject forKey:aKey];
});
}

- (void)removeObject:(id)object {
dispatch_barrier_sync(self.dispatchQueue, ^{
dispatch_barrier_async(self.dispatchQueue, ^{
for (NSString *key in self.dictionary) {
if (object == self.dictionary[key]) {
[self.dictionary removeObjectForKey:key];
Expand All @@ -91,19 +91,19 @@ - (void)removeObject:(id)object {
}

- (void)removeObjectForKey:(id)aKey {
dispatch_barrier_sync(self.dispatchQueue, ^{
dispatch_barrier_async(self.dispatchQueue, ^{
[self.dictionary removeObjectForKey:aKey];
});
}

- (void)removeAllObjects {
dispatch_barrier_sync(self.dispatchQueue, ^{
dispatch_barrier_async(self.dispatchQueue, ^{
[self.dictionary removeAllObjects];
});
}

- (void)mutateWithBlock:(void (^)(NSMutableDictionary *))block {
dispatch_barrier_sync(self.dispatchQueue, ^{
dispatch_barrier_async(self.dispatchQueue, ^{
block(self.dictionary);
});
}
Expand All @@ -112,7 +112,7 @@ + (void)mutateSyncedDictionaries:(NSArray<AWSSynchronizedMutableDictionary *> *)
AWSSynchronizedMutableDictionary *first = [dictionaries firstObject];
if (!first) { return; }

dispatch_barrier_sync(first.dispatchQueue, ^{
dispatch_barrier_async(first.dispatchQueue, ^{
[dictionaries enumerateObjectsUsingBlock:^(AWSSynchronizedMutableDictionary * _Nonnull atomicDictionary, NSUInteger index, BOOL * _Nonnull stop) {
NSCAssert([first.syncKey isEqual:atomicDictionary.syncKey], @"Sync keys much match");
block(atomicDictionary.instanceKey, atomicDictionary.dictionary);
Expand Down
4 changes: 2 additions & 2 deletions AWSIoT/Internal/AWSIoTMQTTClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,8 @@ - (void)cleanupReconnectTimer {
}

if (self.reconnectThread) {
if ( ![[NSThread currentThread] isEqual:self.reconnectThread]) {
// Move to reconnect thread to cleanup
if (!self.reconnectThread.isFinished && ![[NSThread currentThread] isEqual:self.reconnectThread]) {
// Move to reconnect thread to cleanup only if it's still running
[self performSelector:@selector(cleanupReconnectTimer)
onThread:self.reconnectThread
withObject:nil
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

## Unreleased

-Features for next release
- **AWSCore**
- Fixing concurrency issues in `AWSSynchronizedMutableDictionary` (#5413)

- **AWSIoT**
- Fixing random crash when a connection is attempted just after disconnecting

## 2.36.6

Expand Down

0 comments on commit 21daae9

Please sign in to comment.