ASIdentifierManager.advertisingIdentifier hanging

Is there any threading assumption/requirement for ASIdentifierManager.advertisingIdentifier?

Please see the complete issue and stack trace here. The main thread was waiting for the worker thread, which was blocked in ASIdentifierManager.advertisingIdentifier.

Thread 68:
0 libsystem_kernel.dylib 0x188abf0f4 mach_msg_trap (in libsystem_kernel.dylib) + 8
1 libsystem_kernel.dylib 0x188abe5a0 mach_msg (in libsystem_kernel.dylib) + 72
2 libdispatch.dylib 0x188924880 _dispatch_mach_send_and_wait_for_reply (in libdispatch.dylib) + 500
3 libdispatch.dylib 0x188924d10 dispatch_mach_send_with_result_and_wait_for_reply$VARIANT$mp (in libdispatch.dylib) + 52
4 libxpc.dylib 0x188b8391c xpc_connection_send_message_with_reply_sync (in libxpc.dylib) + 204
5 Foundation 0x189aafa28 NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY (in Foundation) + 12
6 Foundation 0x189892f60 -[NSXPCConnection sendInvocation:orArguments:count:methodSignature:selector:withProxy:] (in Foundation) + 3608
7 CoreFoundation 0x188f3276c forwarding (in CoreFoundation) + 552
8 CoreFoundation 0x188f3475c forwarding_prep_0 (in CoreFoundation) + 92
9 CoreServices 0x1b1896ce4 -[LSApplicationWorkspace deviceIdentifierForAdvertising] (in CoreServices) + 160
10 AdSupport 0x198f70a60 -[ASIdentifierManager advertisingIdentifier] (in AdSupport) + 56

I don't see any thread related information in the document. I tried to recreate the scenario, but I could not reproduce the issue with the simplified test below.

#import "ViewController.h"

#import "AdSupport/AdSupport.h"
#import "AppTrackingTransparency/AppTrackingTransparency.h"

@interface ViewController () {
 dispatch_queue_t _queue;
}
@end

@implementation ViewController

- (void)viewDidLoad {
 [super viewDidLoad];

 _queue = dispatch_queue_create("IdentityWorkerQueue", DISPATCH_QUEUE_SERIAL);
 dispatch_set_target_queue(_queue,
              dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0));

 if (@available(iOS 14, *)) {
  [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:
   ^(ATTrackingManagerAuthorizationStatus status) {
   NSLog(@"Status: %lu", (unsigned long)status);
  }];
 }
}

- (IBAction)action:(id)sender {
 __block NSString *adId1 = nil;
 dispatch_async(self->_queue, ^{
  sleep(1);
  adId1 = ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString;
 });

 __block NSString *adId2 = nil;
 dispatch_sync(self->_queue, ^{
  adId2 = adId1;
 });
}

@end

Is there any threading assumption/requirement for ASIdentifierManager.advertisingIdentifier? For example, would it wait for the main thread to finish a certain task when an error happens?

I also ran into an (a crash in our case) when accessing ASIdentifierManager off the main thread; I suspect it has an undocumented main thread requirement. Reported to apple: FB14569567

ASIdentifierManager.advertisingIdentifier hanging
 
 
Q