Skip to content

Commit

Permalink
Wrap encoder recreation in barrier block to avoid race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasz-szyszkowski committed Nov 5, 2021
1 parent d370c10 commit 0a7fd0c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions Source/ARTChannel.m
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ - (void)setOptions_nosync:(ARTChannelOptions *)options {
}

- (void)recreateDataEncoderWith:(ARTCipherParams*)cipher {
NSError *error = nil;
_dataEncoder = [[ARTDataEncoder alloc] initWithCipherParams:cipher error:&error];

if (error != nil) {
[_logger warn:@"creating ARTDataEncoder: %@", error];
_dataEncoder = [[ARTDataEncoder alloc] initWithCipherParams:nil error:nil];
}
dispatch_barrier_async(_queue, ^{
NSError *error = nil;
self->_dataEncoder = [[ARTDataEncoder alloc] initWithCipherParams:cipher error:&error];

if (error != nil) {
[self->_logger warn:@"creating ARTDataEncoder: %@", error];
self->_dataEncoder = [[ARTDataEncoder alloc] initWithCipherParams:nil error:nil];
}
});
}

- (void)publish:(NSString *)name data:(id)data {
Expand Down

0 comments on commit 0a7fd0c

Please sign in to comment.