You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Any time I try to mutate the cache, my app immediately crashes. It is always crashing at the same spot (line 153 of ApolloStore.swift).
Version
1.21.0
Steps to reproduce the behavior
Run app on simulator or real device
Execute any function that will mutate the cache
Minimum Deployments:
iOS 18.2
macOS 15.2
Currently running on Xcode 16.3
Below are some implementation details:
Client
private(set) lazy var apollo: ApolloClient = {
let client = URLSessionClient()
let cache = InMemoryNormalizedCache()
let store = ApolloStore(cache: cache)
let provider = NetworkInterceptorProvider(client: client, store: store)
let url = URL(string: AppInfo.defaultServer)!
let transport = RequestChainNetworkTransport(interceptorProvider: provider, endpointURL: url)
return ApolloClient(networkTransport: transport, store: store)
}()
Apollo Interceptor
class apolloInterceptorClassName: ApolloInterceptor {
public var id: String = UUID().uuidString
func interceptAsync<Operation>(
chain: RequestChain,
request: HTTPRequest<Operation>,
response: HTTPResponse<Operation>?,
completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void
) where Operation : GraphQLOperation {
if let token = Keychain.shared.keychain.get(AppInfo.userTokenKey) {
request.addHeader(name: "Authorization", value: token)
}
print(request.additionalHeaders)
chain.proceedAsync(
request: request,
response: response,
interceptor: self,
completion: completion)
}
}
class interceptorProviderClassName: DefaultInterceptorProvider {
override func interceptors<Operation>(for operation: Operation) -> [ApolloInterceptor] where Operation : GraphQLOperation {
var interceptors = super.interceptors(for: operation)
interceptors.insert(AuthorizationInterceptor(), at: 0)
return interceptors
}
}
Schema Configuration
public enum SchemaConfiguration: ApolloAPI.SchemaConfiguration {
public static func cacheKeyInfo(for type: ApolloAPI.Object, object: ApolloAPI.ObjectData) -> CacheKeyInfo? {
switch type {
default:
guard let id = object["id"] as? Int else {
return nil
}
return CacheKeyInfo(id: String(id), uniqueKeyGroup: type.typename)
// return try? CacheKeyInfo(jsonValue: object["id"])
}
}
}
Mutable Fragment Definition
fragment MutableMediaDetails on Media
@apollo_client_ios_localCacheMutation {
id
isFavourite
}
I am able to fetch the data fine. When I perform the mutation, the data is updating on the server correctly, but after completing the mutation and I try to update the cache, the app crashes immediately. ApolloStore.swift line 153 crash
public func withinReadWriteTransaction<T>(
_ body: @escaping (ReadWriteTransaction) throws -> T,
callbackQueue: DispatchQueue? = nil,
completion: ((Result<T, any Swift.Error>) -> Void)? = nil
) {
self.queue.async(flags: .barrier) {
do {
let returnValue = try body(ReadWriteTransaction(store: self)) <-- CRASHES HERE!!
DispatchQueue.returnResultAsyncIfNeeded(
on: callbackQueue,
action: completion,
result: .success(returnValue)
)
} catch {
DispatchQueue.returnResultAsyncIfNeeded(
on: callbackQueue,
action: completion,
result: .failure(error)
)
}
}
}
Thanks for the report @arvinshen. Sorry we missed your thread in the Apollo Community, I'm not sure how that one slipped by us.
This is crashing with a failed assertion in swift_task_isCurrentExecutorImpl. I'm not 100% sure what is going on here, and I'd need to see more of your code where you are actually calling withinReadWriteTransaction to get a better sense of what's going wrong here.
It's likely that you are calling into this from an isolated context which is causing the assertion failure. I'm working on Apollo iOS version 2.0 right now, which will be more compatible with the new Swift Concurrency model and this shouldn't be an issue anymore. But for now, ApolloStore uses an underlying dispatch queue to manage its own thread safety, so you'll want to make calls into it from a nonisolated context.
Summary
Any time I try to mutate the cache, my app immediately crashes. It is always crashing at the same spot (line 153 of ApolloStore.swift).
Version
1.21.0
Steps to reproduce the behavior
Minimum Deployments:
iOS 18.2
macOS 15.2
Currently running on Xcode 16.3
Below are some implementation details:
Client
Apollo Interceptor
Schema Configuration
Mutable Fragment Definition
I am able to fetch the data fine. When I perform the mutation, the data is updating on the server correctly, but after completing the mutation and I try to update the cache, the app crashes immediately.
ApolloStore.swift line 153 crash
Logs
Anything else?
I posted about this in the Apollo Community but received zero replies.
The text was updated successfully, but these errors were encountered: