From 3874d65ec20ca7acc2d6dd655c017eab8b2263b0 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Sun, 9 Mar 2025 15:05:03 -0700 Subject: [PATCH] Bug Fix: Operation blocks should queue inputs Operation blocks cannot expect their out of scope variables to be present when the block executes, so design the block operation to pull inputs from a queue array one at a time, like the rest of the blocks do. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistLoader.m | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 1c57076da..5b5cbbc8e 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -908,12 +908,19 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); __block id mainTask = [SentrySDK startTransactionWithName:@"Loading tags" operation:@"Main tag operation"]; { - for(NSString *key in queueThisJob) { + __block NSLock *blockLock = [[NSLock alloc] init]; + __block NSMutableArray *blockInputs = [queueThisJob mutableCopy]; + for(size_t i = 0, j = [blockInputs count]; i < j; ++i) { NSBlockOperation *op = [[NSBlockOperation alloc] init]; - NSURL *url = urlForPath(key); - [op addExecutionBlock:^{ @autoreleasepool { + [blockLock lock]; + NSString *key = [blockInputs objectAtIndex:0]; + [blockInputs removeObjectAtIndex:0]; + [blockLock unlock]; + + NSURL *url = urlForPath(key); + NSString *message = [NSString stringWithFormat:@"Loading metadata for %@", url]; DLog(@"%@", message); id childTask = nil; @@ -947,7 +954,11 @@ NSURL *_Nullable urlForPath(NSString *_Nullable path); } @catch(NSException *e) { DLog(@"Exception thrown while reading tags: %@", e); - [SentrySDK captureException:e]; + if(e) { + [SentrySDK captureException:e]; + } else { + [SentrySDK captureMessage:[NSString stringWithFormat:@"Null exception caught while reading tags for URL: %@", url]]; + } if(childTask) { [childTask finishWithStatus:kSentrySpanStatusInternalError]; }