Got a crash from a user “system has no mach ports available”. Checking the crash log I see some information about ports
[quote]0 com.apple.CoreFoundation 0x00007fff36d7ddb7 THE_SYSTEM_HAS_NO_PORTS_AVAILABLE + 4
1 com.apple.CoreFoundation 0x00007fff36c7874c __CFRunLoopCreate + 555
2 com.apple.CoreFoundation 0x00007fff36c78499 _CFRunLoopGet0 + 194[/quote]
But there also is a thread on printing
[quote]12 com.apple.AppKit 0x00007fff3455be71 -[NSPrintInfo(NSInternal) _printSessionForGetting] + 43
13 com.apple.AppKit 0x00007fff345619d8 -[NSPrintInfo(NSInternal) _createDefaultOrUnflattenPrintSettingsIfNecessary] + 188
14 com.apple.AppKit 0x00007fff345618f0 -[NSPrintInfo(NSInternal) _printSettingsForSetting] + 22
15 com.apple.AppKit 0x00007fff3492ffcb -[NSConcretePrintOperation runOperation] + 514
16 MBS_MacControls_HTMLViewerPrint_Plugin_19729.dylib 0x0000000109e1e45b PrintToPDFFile(REALobjectStruct*, REALfolderItemStruct*, double, double, double, double) + 1323
17 com.mothsoftware.mailarchiverx 0x0000000101fe34af HTMLViewerHTMLViewerPrintExtensionMBS.$PrintToPDFFileMBS%b%oof8f8f8f8 + 111[/quote]
So I think that printing is somehow messing up the mach ports. After some emails exchanged with Christian and further testing it seems that executing AppleScripts with Mail as target is opening mach ports by the dozen. Those are closed very slowly as I can see in the Activity Viewer. It’s not even my app. Simply executing a script in the ScriptViewer
property Mailbox0 : "iCloud"
property Mailbox1 : "Newsletters"
property currentMessageStr : "1"
with timeout of 10000 seconds
set currentMessage to currentMessageStr as integer
set AllHeaders to {}
tell application id "com.apple.mail"
try
repeat with messageNo from currentMessage to currentMessage + 9
set theMessage to (message messageNo of mailbox (Mailbox1) of account (Mailbox0))
if not deleted status of theMessage then
set theRes to (all headers of theMessage)
if theRes = "" then
copy ("empty") to end of AllHeaders
else
copy theRes to end of AllHeaders
end if
else
copy ("deleted") to end of AllHeaders
end if
end repeat
return AllHeaders
on error errMsg number errNr
if errNr = -1719 then
return AllHeaders
end if
end try
end tell
end timeout
opens like 20 - 30 mach ports per single execution. My app can do this hundreds or thousands of times.
I’m not an expert in low level macOS stuff. From Goggling I think that mach ports are used for low level communication. But I haven’t the foggiest what those things are.
Questions: can I change the number of available mach ports? Can I force/encourage Mail to close the mach ports faster?