AppleEvents errors in 10.13

I'm the developer of SmashTunes (an app to control iTunes and Spotify). Since the latest beta of 10.13, I'm seeing a lot of errors being logged:


10759711: Error #17  (os/kern) invalid right attempting to add send right to port ( port:33051/0x811b rcv:1,send:0,d:0 limit:5).
AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.


SmashTunes use ScriptingBridge for its communication with iTunes and Spotify. I'm suspecting this may have to do something with my entitlements file (which I think should be correct). The "funny" thing is, that the app is still functioning correctly (although a bit slow). So, the AppleScript is correclty executed by both Spotify and iTunes.


Anyone seen this before?

Replies

Since the latest beta of 10.13 …

10.13 GM was released yesterday. You should definitely re-test on that (although I doubt it’ll change things).

Also, please clarify what you mean by “Since the latest beta”? Does that mean that it worked on previous 10.13 betas? If so, where was the inflection point?

I'm seeing a lot of errors being logged …

Where are you seeing these errors? In the Xcode console pane? Or in the Console app?

This matters because the first error looks like a problem with the send and the second looks like a problem with the receive, so I’d like to confirm which processes are generating which errors.

The error 17 in the first message is probably

KERN_INVALID_RIGHT
, meaning that someone is trying to send a Mach message that includes a right but the right is invalid. In and of itself that’s not particularly useful but it may be a useful clue in subsequent investigations.

Finally, am I right in assuming that this problem affects your existing product? That is, if you take your currently shipping product and put it on 10.12.x it works just fine but on 10.13 it performs poorly and logs these errors? If so, you should definitely file a binary compatibility bug about the problem, regardless of what else you do.

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Hi Eskimo,


I was testing against the latest beta, that was marked as GM. I see now, a new build was posted.

The logging was from the console (and identical in XCode). I'll retest first and see what has changed / improved.


Thanks for your suggestions!

Hmm. I tried to update from version 17A362a to 17A365, but after installing the update I'm still at 17A362a...

I'll file a bug report.

Hi Eskimo,


I've filed a bug report (34691166). The problem is still present in 10.13.1 (beta). I've mentioned current version of product and relevant build of macOS, I could not find a specific field or option to indicatate that this is a "binary compatibility bug". I guess I'll have to wait and see.

I've filed a bug report (34691166).

Thanks for that.

I could not find a specific field or option to indicatate that this is a "binary compatibility bug".

Indeed. I generally just say “The same program worked fine on *** but now fails on yyy.”

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

I am seeing this on a 10.13 running XC 9.

Never saw such a thing before this...

AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.

Here's some details


Having defined:

on populateURLMenu()
    set theResult to {}
    try
        if application "Safari" is running then
            tell application "Safari"
                set wc to count of every window
                repeat with i from 1 to wc
                    tell window i
                        try
                            set tabCount to count of every tab
                            if tabCount > 0 then
                                repeat with j from 1 to tabCount
                                    set thisTab to tab j
                                    set theURL to (URL of thisTab) as string
                                    if ((length of theURL > 0) and ((theURL begins with "http") or (theURL begins with "file"))) then
                                        set end of theResult to {|window|:i as text, |tab|:j as text, |name|:name of thisTab, |url|:theURL, |text|:text of thisTab, |source|:""}
                                    end if
                                end repeat
                            end if
                        end try
                    end tell
                end repeat
            end tell
        end if
        on error errMsg number errNum
        set theResult to "Error#: " & (errNum as text) & " " & errMsg
    end try
    return theResult
end populateURLMenu
...
#define kASAppleScriptSuite (FourCharCode)'ascr'
#define kASSubroutineEvent (FourCharCode)'psbr'
#define keyASSubroutineName (FourCharCode)'snam'

...
+ (NSAppleEventDescriptor *) callSub:(NSString *)handler params:(NSAppleEventDescriptor *)firstParam, ... {
    NSAppleEventDescriptor* list = [NSAppleEventDescriptor listDescriptor];
    int i=0; va_list ppp; va_start(ppp, firstParam);
    NSAppleEventDescriptor * aParam = firstParam;
    while (aParam) {
        [list insertDescriptor:aParam atIndex:++i];
        aParam = va_arg(ppp, NSAppleEventDescriptor *);
    }
    NSAppleEventDescriptor *h = [NSAppleEventDescriptor descriptorWithString:handler.lowercaseString];
    NSAppleEventDescriptor *ae = [NSAppleEventDescriptor appleEventWithEventClass:kASAppleScriptSuite eventID:kASSubroutineEvent targetDescriptor:[NSAppleEventDescriptor nullDescriptor] returnID:kAutoGenerateReturnID transactionID:kAnyTransactionID];
    [ae setParamDescriptor:h forKeyword:keyASSubroutineName];
    [ae setParamDescriptor:list forKeyword:keyDirectObject];
    return ae;
}
    return ae;
}


Then executing:

NSDictionary *errorDict = nil;
    NSString * p = [[NSBundle mainBundle] pathForResource:resource ofType:@"scpt"];
    NSLog(@"p: %@",p);
    NSAppleScript * aScript = [[NSAppleScript alloc] initWithContentsOfURL:[NSURL fileURLWithPath:p] error:nil];
    NSLog(@"aScript: %@",aScript);
    NSAppleEventDescriptor * aEvent = [MacEnactAppleScriptTool callSub:scriptName params:nil];
    NSLog(@"aEvent: %@",aEvent);
    NSAppleEventDescriptor * eventDescriptor = [aScript executeAppleEvent:aEvent error:&errorDict];
    if ((!eventDescriptor.descriptorType) || (errorDict!=nil)) {
        if (!eventDescriptor.descriptorType) return @[@{@"ERROR":@"badDescriptor"}];
        else return @[errorDict];
    }
    else {
        return [MacEnactAppleScriptTool arrayOfDictionariesFromAppleEventDescriptor:eventDescriptor];
    }


Returns the expected results AND

Puts this into the console:

2017-09-28 18:20:50.560998-0700 Enact[5863:3858064] p: /Users/steve/Library/Developer/Xcode/DerivedData/Enact-eqdlomprzlmolpcdjapdhdvuixld/Build/Products/Debug/Enact.app/Contents/Resources/EnactAppleSafari.scpt
2017-09-28 18:20:50.620257-0700 Enact[5863:3858064] aScript: <NSAppleScript: 0x60000045dfa0>
2017-09-28 18:20:50.633716-0700 Enact[5863:3858064] aEvent: <NSAppleEventDescriptor: 'ascr'\'psbr'{ 'snam':'utxt'("populateurlmenu"), '----':[  ] }>
2017-09-28 18:20:50.650149-0700 Enact[5863:3858064] AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.
2017-09-28 18:20:50.668416-0700 Enact[5863:3858064] browser update: NSConcreteNotification 0x60000044d7d0 {name = ApplicationActivationNotification; object = NSConcreteNotification 0x60c00004f420 {name = NSWorkspaceDidActivateApplicationNotification; object = <NSWorkspace: 0x6040000003d0>; userInfo = {
    NSWorkspaceApplicationKey = "<NSRunningApplication: 0x60c00010a320 (com.apple.dt.Xcode - 3626)>";
}}}
2017-09-28 18:20:50.704593-0700 Enact[5863:3858064] AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.
2017-09-28 18:20:50.713186-0700 Enact[5863:3858064] AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.
2017-09-28 18:20:50.722864-0700 Enact[5863:3858064] AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.
….


Running the script in Script Editor similary spews 'complex' msgs - it also retrieves the correct results..

same probem for me when controlling iTunes over the scriptingbridge.

i'm using now the release version hihg sierra (macOS 10.13 (17A365))

my app is freezing for seconds and sometimes for minutes in the AESendMessage when this happens



the call stack trace looks like this



* thread #1, name = 'MeMyselfAndIAppMainThread', queue = 'com.apple.main-thread', stop reason = signal SIGSTOP

frame #0: 0x00007fff68112e76 libsystem_kernel.dylib`mach_msg_trap + 10

frame #1: 0x00007fff68112390 libsystem_kernel.dylib`mach_msg + 60

frame #2: 0x00007fff40a6c475 CoreFoundation`__CFRunLoopServiceMachPort + 341

frame #3: 0x00007fff40a6b7c7 CoreFoundation`__CFRunLoopRun + 1783

frame #4: 0x00007fff40a6ae43 CoreFoundation`CFRunLoopRunSpecific + 483

frame #5: 0x00007fff41b648c8 AE`waitForReply(unsigned int, WaitForReplyElem*, unsigned int, unsigned int) + 708

frame #6: 0x00007fff41b38171 AE`AESendMessage + 2963

frame #7: 0x00007fff4c59ac64 ScriptingBridge`-[SBAppContext sendEvent:error:] + 78

frame #8: 0x00007fff4c5947db ScriptingBridge`-[SBObject sendEvent:id:parameters:] + 452

frame #9: 0x00007fff4c5a1bc7 ScriptingBridge`getter_thunk + 86

frame #10: 0x00007fff669f69f3 libffi.dylib`ffi_closure_unix64_inner + 487

frame #11: 0x00007fff669f60e6 libffi.dylib`ffi_closure_unix64 + 70

* frame #12: 0x0000000100092067 Smart Tunes`::-[CiTunesManager findTrackIn:byID:](self=0x0000604000105100, _cmd="findTrackIn:byID:", tracks=0x000060800002ae60, trackID="205A30AFCD5B73E4") at CiTunesManager.mm:189

frame #13: 0x0000000100093258 Smart Tunes`::-[CiTunesManager restoreItunesStateIfAllowed](self=0x0000604000105100, _cmd="restoreItunesStateIfAllowed") at CiTunesManager.mm:255

frame #14: 0x00000001000926d6 Smart Tunes`::__40-[CiTunesManager canPlayAgainDoRestore:]_block_invoke((null)=<unavailable>) at CiTunesManager.mm:216

frame #15: 0x0000000101211f1f libdispatch.dylib`_dispatch_client_callout + 8

frame #16: 0x00000001012265be libdispatch.dylib`_dispatch_continuation_pop + 940

frame #17: 0x000000010121461b libdispatch.dylib`_dispatch_source_invoke + 658

frame #18: 0x000000010121e1e7 libdispatch.dylib`_dispatch_main_queue_callback_4CF + 1135

frame #19: 0x00007fff40aa9869 CoreFoundation`__CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9

frame #20: 0x00007fff40a6baea CoreFoundation`__CFRunLoopRun + 2586

frame #21: 0x00007fff40a6ae43 CoreFoundation`CFRunLoopRunSpecific + 483

frame #22: 0x00007fff3fd8a866 HIToolbox`RunCurrentEventLoopInMode + 286

frame #23: 0x00007fff3fd8a5d6 HIToolbox`ReceiveNextEventCommon + 613

frame #24: 0x00007fff3fd8a354 HIToolbox`_BlockUntilNextEventMatchingListInModeWithFilter + 64

frame #25: 0x00007fff3e08844f AppKit`_DPSNextEvent + 2085

frame #26: 0x00007fff3e81d508 AppKit`-[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 3044

frame #27: 0x00007fff3e07d25d AppKit`-[NSApplication run] + 764

frame #28: 0x00007fff3e04c3fe AppKit`NSApplicationMain + 804



any progress on this problem?



TIA!

Hofi

Just a quick update, removing the app's sandbox entitlements will not remove the error messages but at least prevent the app freezing in the AESendMessage (just a workaround if sandboxing is not a requirement, which is not my case unfortunately :/)


Forgot to add my bug report ID: 34812996

Seeing these errors and freezes as well, when controlling the "Photos App" over AppleScript on High Sierra.

Even exexuting a simple script as

tell application "Photos"
  containers
end tell

in the AppleScript Editor makes the Photos App hang, when the Photos App has not been started prior to executing the script.

Reported as Radar: 34638625

I would like to confirm the same problem of an existing and published app, which worked fine with macOS 10.12.x


[main] 10759711: Error #17  (os/kern) invalid right attempting to add send right to port ( port:99679/0x1855f rcv:1,send:0,d:0 limit:5).
AppleEvents: received mach msg which wasn't complex type as expected in getMemoryReference.

Can you please all file radars on these bugs? This is the only way it will get attention from the actual macOS developers. Something seems to be really broken in Apple-Script Support in High Sierra.

macOS 10.13 (17A405) still not solved the issue yet unfortunately :/

My radr was marked as a duplicate of 34634383 and closed today.

My radr was marked as a duplicate of 34634383 and closed today.

Thanks for the update. I took a look at that bug and it seems to be an actual bug in the OS, something that will need to be fixed in a 10.13 software update.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"