I just had a customer reporting the same issue with getattrlistbulk and ERANGE: Result too large. According to them, it happens on macOS 10.13 with APFS but doesn't happen on macOS 10.14 anymore.
I can also confirm that it only happens when the last call exactly fills the buffer. Running FileManager.contentsOfDirectory(atPath:) returns the cumulative amount of entries processed with getattrlistbulk and throws no error.
Post
Replies
Boosts
Views
Activity
Why do you say preferred 1KB, when in the same sentence you say the preferred block size is 1MB?
Sorry, my mistake. Let me give you some actual results: when using the "preferred" 1_048_576 block size (returned by URLResourceKey.preferredIOBlockSizeKey) it takes about 6.15 seconds to copy a 7 GB file from my Mac to another folder on the same Mac. When using 16_777_216 block size, I get about 3 seconds instead. If I don't set the block size option for filecopy, I get about the same time as with the preferred block size, so I guess it's probably the same value.
My question is: what makes the 1_048_576 block size "preferred", since using 16_777_216 drastically increases the filecopy performance? And can we assume that increasing the block size will always give better performance for filecopy?
Thanks a lot for your valuable input!
Things will go better if your block size matches the allocation block size of the underlying volume
When you say "match", do you mean equal, or a multiple, or something else? I'm asking because the value returned by URLResourceKey.preferredIOBlockSizeKey for my Macintosh HD is 1048576, but significantly increasing the block size of filecopy from the "preferred" 1KB to 1MB or higher usually performs better.
On the one hand, I’d like you to open a DTS tech support incident so that I can dig into this
OK, I opened Case-ID: 5366675.
You should file a bug to request clarification from Apple
I already filed FB13397779 some weeks ago, but didn't get a response.
Are only seeing this with mDNSResponder flows?
The majority is /usr/sbin/mDNSResponder, but I also get others, such as /usr/sbin/netbiosd.
(r. 115822797)
Can I look this somewhere up, or is it just for your own reference?
Do you think this behaviour is a bug, or does it mean that the earlier flow is invalid once the double one comes in, or what does it mean?
It’s probably worth filing a bug about that. Please post your bug number, just for the record.
I created FB13454498.
First, I recommend against using Dispatch global concurrent queues, as explained in Avoid Dispatch Global Concurrent Queues.
Thank you. While the second WWDC link on the linked page correctly leads to a video, the first link (WWDC 2015 Session 718 Building Responsive and Efficient Apps with GCD) leads to a list of videos where that video cannot be found. Does it still exist?
Second, synchronously dispatching to the main queue is a concern because it can block the current thread for long periods of time.
I know, but that thread needs access to a resource possibly occupied by the main thread before being able to continue with its work.
I think you’d be much better off investing in Swift concurrency.
I'm still supporting macOS 10.13, while Swift concurrency is only available on macOS 10.15.
I forgot to mention that I'm doing this from a background thread:
DispatchQueue.global().async {
DispatchQueue.main.async { [self] in
asd() // no warning or error
}
DispatchQueue.main.sync { [self] in
asd() // warning: Call to method 'asd' in closure requires explicit use of 'self' to make capture semantics explicit; this is an error in Swift 6
}
}
Shouldn't you be using self?.asd() in the closure for weak self?
Not necessarily. One could use
guard let self = self else {
return
}
to avoid using self?. each time. But I don't need to use weak self in this case.
You could test this.
I manually caused an infinite recursion at the same location as the other crash report and I got a crash report with 511 frames. Frames numbered 9 to 510 are all the same, and since 510 is the last one, it looks like it's cut off. Otherwise the frames look very similar to the crash report downloaded by Xcode.
Thread 4 Crashed:: Dispatch queue: com.apple.root.user-initiated-qos
0 CoreFoundation 0x1837f5084 __CFStringEncodeByteStream + 76
1 Foundation 0x184901558 -[NSString(NSStringOtherEncodings) getBytes:maxLength:usedLength:encoding:options:range:remainingRange:] + 260
2 libswiftCore.dylib 0x1931cf194 _NSStringCopyBytes(_:encoding:into:) + 124
3 libswiftCore.dylib 0x1931d67f0 _StringGuts._foreignCopyUTF8(into:) + 80
4 libswiftCore.dylib 0x1931d7bc8 _StringGuts._foreignConvertedToSmall() + 68
5 libswiftCore.dylib 0x1931d7b44 _StringGuts.append(_:) + 1232
6 libswiftCore.dylib 0x19316ba80 String.write<A>(to:) + 56
7 libswiftCore.dylib 0x19300bef0 DefaultStringInterpolation.appendInterpolation<A>(_:) + 72
8 MyApp 0x1000e4538 String.appendingPathComponent(_:) + 924 (PathAdditions.swift:75)
9 MyApp 0x100119138 Snapshot.renameFile(_:to:) + 696 (Snapshot+Modify.swift:135)
10 MyApp 0x10011915c Snapshot.renameFile(_:to:) + 732 (Snapshot+Modify.swift:135)
...
510 MyApp 0x10011915c Snapshot.renameFile(_:to:) + 732 (Snapshot+Modify.swift:135)
And it's also the same exception type:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000170027fd8
Exception Codes: 0x0000000000000002, 0x0000000170027fd8
Termination Reason: Namespace SIGNAL, Code 10 Bus error: 10
Terminating Process: exc handler [66786]
VM Region Info: 0x170027fd8 is in 0x170024000-0x170028000; bytes after start: 16344 bytes before end: 39
REGION TYPE START - END [ VSIZE] PRT/MAX SHRMOD REGION DETAIL
Stack 16ff9c000-170024000 [ 544K] rw-/rwx SM=PRV thread 3
---> STACK GUARD 170024000-170028000 [ 16K] ---/rwx SM=NUL ... for thread 4
Stack 170028000-1700b0000 [ 544K] rw-/rwx SM=PRV thread 4
I guess we solved the mystery? Probably the backtrace got cut off along the way between the user and my Xcode instance.
Thank you very much for your help!
I recommend that you update your bug with information about your specific use case.
Thanks, updated it. It's an app that scans user-selected directories, such as Macintosh HD, and shows the contents as a graph.
Thank you very much for your insights.
How did thread 1 get started?
You're right, I didn't notice that the stacktrace looks strange. The code in thread 1 is called from inside NSFileCoordinator.coordinate(readingItemAt:options:writingItemAt:options:error:byAccessor:), which in turn is called inside DispatchQueue.global(qos: .userInitiated).async, with some other of my code before and after each of these calls.
What’s up with the symbolication?
I'm not sure I understand why the double line 135 seems unlikely. I can confirm that in this case it's a recursive method call. Could it be that the program somehow went into infinite recursion, explaining why the thread's origin is cut off?
Thanks, attached the full crash report.
crash.txt
The privilege to access other apps containers falls into that third group.
Thanks for confirming. Personally, I think it's quite annoying that it gets shown each time, and the reason why I noticed this in the first place was that users of my app where asking me why the alert is shown each time they scan the disk, given that one is used to seeing this kind of alert only once. I have filed FB13410100 in case you're interested.
How is your app signed? A problem with the signature might prevent the OS from "remembering" that permission has been granted before.
Thanks for the suggestion, but I don't think there's any problem with the signature. All other warnings (Calendar, Reminders, etc.) only get shown once, but this one gets shown each time. I think it only started appearing since macOS 14 Sonoma.
While I was writing my earlier answer I just got 10 new flows from 0.0.0.0 to 192.168.1.1 by /sbin/ping: socketType = SOCK_RAW, socketFamily = AF_INET, socketProtocol = IPPROTO_ICMP.