My little network extension is running out of file descriptors. My suspicion is that something in the Security framework is not being deallocated, although even this doesn't make a great deal of sense:
The extension looks at each flow, and gets a SecStaticCodeRef
for it, finds the pathname, makes a decision, and stores the result of that decision in an NSCache<NSData, NSNumber>
where the key is flow.metaData.sourceAppUniqueIdentifier
. This goes through a couple layers of abstractions (the cache is in one Swift class, and it calls another Swift class that gets the security info and then returns the pathname, or throws an error).
As an example, after running for a couple of days, it has 1074 open file descriptors for /System/Library/PrivateFrameworks/CloudKitDaemon.framework/Support/cloudd
-- and only had 732 three hours ago.
Hello!
One of the ways to tack file descriptors is using File Activity template in Instruments. It could be done with following steps:
- Open Instruments;
- Select the extension as a target;
- Open File Activity template;
- Start recording;
- Try to reproduce the issue;
- Stop recording;
- Click on Filesystem Activity track on the top;
- Click on Filesystem Statistics popup menu on the toolbar of details below;
- Select File Descriptor History.
In details view file descriptor events with backtraces should be appeared. The data could by filtered out for event about suspected file by using Detail Filter.
Anton