ursus
07/07/2021, 4:15 PMfun OkhttpAuthenticator.authenticate() {
...
synchronized(this) {
runBlocking { retrofitService.suspendingRefreshTokens() }<---
...
}
}
Could this get broken somehow? runBlocking seems to swap to caller thread context after the network call, so the mutex should be released
or is it not guaranteed? (Because I see certain bugs in production where the code just stops; and not sure if its runBlocning or retrofit related)bezrukov
07/08/2021, 9:16 AMOkhttpAuthenticator.authenticate()
is invoked in okhttp's Interceptor/Authenticator and retrofitService
uses the same okhttpclient it might be related to okhttp's Dispatcher (see maxRequests/maxRequestsPerHost).ursus
07/08/2021, 10:59 AMbezrukov
07/08/2021, 11:14 AMif I made it synchronous and on caller thread, it should be okay, right?yep should be ok, blocking calls bypass okhttp executor. Another option is to setup retrofit service for token refresh with dedicated okhttp dispatcher
ursus
07/08/2021, 11:42 AMbezrukov
07/08/2021, 11:47 AMyourOkHttpClient.newBuilder().dispatcher(Dispatcher())
when building your retrofitService serviceursus
07/08/2021, 12:46 PMbezrukov
07/08/2021, 3:07 PMursus
07/08/2021, 3:11 PMbezrukov
07/08/2021, 3:57 PMThreadPoolExecutor(0, Int.MAX_VALUE, 60, TimeUnit.SECONDS, ...
that means this pool will create threads lazily and will keep it only for 60 seconds (once they unused), so I would say it's negligible. Yep, best option would be to call it synchronously on caller threadursus
07/08/2021, 4:12 PMbezrukov
07/09/2021, 6:13 AMursus
07/10/2021, 11:05 AM