New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SR-10554] Crash: Bound function reference to protocol existential has nil self when invoked #52954
Comments
The high bit is set there, too, so I'm not sure that conclusion is correct. I wonder if it's related to some of the enums-with-one-payload issues that we've seen (cc aschwaighofer@apple.com (JIRA User)). |
Oh huh you're right the high bit is indeed set, it's |
@belkadan or aschwaighofer@apple.com (JIRA User) do you have another Jira for that enums issue you referenced? As an update, users of our app hit this about 1000 times per day. |
Great, thank you! |
Looking at the source code and that other Jira, I don't see how it can be related, but maybe I'm missing something. It seems like that issue was related to single-case enums, but there are no enums in this code? |
We're not sure if it's related. There's not really enough information in this bug to be actionable. |
How can we gather more information? All we have right now is the crash log, the line it occurs on, and the fact that it didn't happen with the Swift 4.2 compiler. |
By "bound protocol function", do you mean something like the case in https://bugs.swift.org/browse/SR-75 ? It could be that you're somehow "lucky" enough that your case miscompiles rather than crashing somewhere inside the compiler. |
Not quite. The code is accessing a bound function like that, except on a protocol existential, not on a protocol type. It's something like protocol NormalizedCache {
func loadRecords(forKeys keys: [CacheKey]) -> Promise<[Record?]>
…
}
class ReadTransaction {
let cache: NormalizedCache
lazy var loader: DataLoader<CacheKey, Record?> = DataLoader(cache.loadRecords)
…
}
class DataLoader<Key, Value> {
let loader: ([Key]) -> Promise<[Value]>
init(_ loader: @escaping ([Key]) -> Promise<[Value]>) {
self.loader = loader
}
…
} So The concrete |
If you've got it narrowed down to that, you've got a potential workaround: use an explicit closure. If that makes it go away, it might be a problem with bound functions on existentials; if it doesn't, it could be a problem with |
The crash isn't in our code, it's in a third-party library that we depend on. And unfortunately the authors of that library are rather nonresponsive to issues so I have very little hope that we'd be able to convince them to change that to a closure. If we knew how to reproduce this crash locally I'd test that as a temporary patch, but I don't think any of us have ever seen this crash ourselves, we've only gotten crash logs from users. |
Got it. :-( |
We manually patched the dependency code to try out that work-around in our latest release, but that did not fix the crash. We changed from:
to:
|
This has now skyrocketed to being our number 1 crasher. |
Attachment: Download
Environment
Xcode 10.2
Swift 5
iPhone OS 12.2 (16E227)
Additional Detail from JIRA
md5: 5c4ddc7a5ab66026df6b9cbe7c230868
Issue Description:
As best as we can figure, the crash we're seeing indicates that
self
isnil
inside a method. The method in question was captured as a bound method from a protocol existential and then invoked later. We can't actually reproduce this ourselves though.I'm fairly certain that this may be a Swift bug because this crash started occurring on the first release of the Twitch app that we submitted with Xcode 10.2 and the Swift 5 compiler (in Swift 5 mode). The previous few releases were built with Xcode 10.1 and Swift 4.2 and didn't exhibit this crash on the same version of the Apollo-ios library.
While it has affected only a small percentage of users on that release, it has become our #1 crash by a factor of 2.
I have attached an Xcode crash log. The crash happens in this line of this file: https://github.com/apollographql/apollo-ios/blob/0928061a06147bf973a921d424a4d871c7c30bf0/Sources/Apollo/InMemoryNormalizedCache.swift#L9 (Both Fabric and Xcode/iTunes Connect crash symbolication agree).
The text was updated successfully, but these errors were encountered: