-
Notifications
You must be signed in to change notification settings - Fork 743
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
Crash in 0.36.0 #1473
Comments
The crash is happening in the Can you share how you're setting up your |
There is nothing interesting to see there. It just check for token validity if it it expired updates it from server and calls back. I will try to trace/fix crash as it's blocking us, but as its another race condition its not going to be simple as I can't even replicate it reliably. Sometimes it crashes every run (tests) sometimes I hit #1376 and sometimes all tests passes without any problem :) |
I can replicate it with example from https://www.apollographql.com/docs/ios/tutorial/tutorial-mutations/ class TokenAddingInterceptor: ApolloInterceptor {
func interceptAsync<Operation: GraphQLOperation>(chain: RequestChain, request: HTTPRequest<Operation>, response: HTTPResponse<Operation>?, completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
DispatchQueue.main.async { [weak self] in
guard self != nil else { return }
chain.proceedAsync(request: request, response: response, completion: completion)
}
}
} |
NetworkFetchInterceptor:32 don't you need P.S. adding cancel didn't stop crash, but still, don't you need it there? (made PR #1476) |
Ok, what's happening is that
I managed to "solve" it by retaining link to chain in |
sorry for spam @designatednerd |
I thought not retaining chain would help class TokenAddingInterceptor: ApolloInterceptor {
func interceptAsync<Operation: GraphQLOperation>(chain: RequestChain, request: HTTPRequest<Operation>, response: HTTPResponse<Operation>?, completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
DispatchQueue.main.async { [weak self, weak chain] in
guard self != nil else { return }
chain?.proceedAsync(request: request, response: response, completion: completion)
}
}
} but that's not the case - it is deallocated before we can update token and call to server never executed |
right - if you let go of the chain there there's nothing hanging on to it, so ARC smashes it. I'm surprised the legacy interceptor provider is getting deallocated - that indicates that the Request Chain Network Transport itself is getting deallocated. I would really like to see how you're setting this stuff up for tests - it seems like maybe something is calling into an old instance of RCNT in different tests. |
class TokenAddingInterceptor: ApolloInterceptor {
func interceptAsync<Operation: GraphQLOperation>(chain: RequestChain, request: HTTPRequest<Operation>, response: HTTPResponse<Operation>?, completion: @escaping (Result<GraphQLResult<Operation.Data>, Error>) -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(1)) { [weak self] in
guard self != nil else { return }
chain?.proceedAsync(request: request, response: response, completion: completion)
}
}
}
let transport = RequestChainNetworkTransport(...)
let apolloClient = ApolloClient(networkTransport: transport, ...)
apolloClient.fetch(query: ...) will make whole app crash in 1 second because Crash will happen because deallocatingin |
this is the crash #1480 |
I guess easy workaround would be to remove force unwrap, but the real problem is that |
Created PR with workaround #1481 but somehow don't fee good about it :) It doe's work, but feels like some code smell |
should I close this? |
I'll close it when it actually ships |
0.37.0 has shipped! |
Bug report
Crash using interceptors
Versions
Please fill in the versions you're currently using:
apollo-ios
SDK version: 0.36.0Steps to reproduce
I have TokenAddingInterceptor that retrieves token from server and asynchronously calls
chain.proceedAsync
. I have check for TokenAddingInterceptor being released to not call up the chain on dealloc, so that's not the case.The text was updated successfully, but these errors were encountered: