potential race conditions

This commit is contained in:
mertalev
2026-01-20 16:45:24 -05:00
parent d898cba04d
commit e51547cd28
2 changed files with 25 additions and 19 deletions
@@ -36,6 +36,7 @@ object SSLConfig {
serverHost: String?,
clientCertHash: Int
) {
synchronized(this) {
val newHash = computeHash(allowSelfSigned, serverHost, clientCertHash)
val newRequiresCustomSSL = allowSelfSigned || keyManagers != null
if (newHash == configHash && sslSocketFactory != null && requiresCustomSSL == newRequiresCustomSSL) {
@@ -51,6 +52,7 @@ object SSLConfig {
configHash = newHash
notifyListeners()
}
}
private fun computeHash(allowSelfSigned: Boolean, serverHost: String?, clientCertHash: Int): Int {
var result = allowSelfSigned.hashCode()
@@ -120,6 +120,7 @@ private object ImageFetcherManager {
}
private fun invalidate() {
synchronized(this) {
val oldFetcher = fetcher
if (oldFetcher is OkHttpImageFetcher && SSLConfig.requiresCustomSSL) {
fetcher = oldFetcher.reconfigure(SSLConfig.sslSocketFactory, SSLConfig.trustManager)
@@ -128,6 +129,7 @@ private object ImageFetcherManager {
fetcher = build()
oldFetcher.drain()
}
}
private fun build(): ImageFetcher {
return if (SSLConfig.requiresCustomSSL) {
@@ -205,6 +207,7 @@ private class CronetImageFetcher(context: Context, cacheDir: File) : ImageFetche
override fun drain() {
val shouldShutdown = synchronized(stateLock) {
if (draining) return
draining = true
activeCount == 0
}
@@ -406,6 +409,7 @@ private class OkHttpImageFetcher private constructor(
override fun drain() {
val shouldClose = synchronized(stateLock) {
if (draining) return
draining = true
activeCount == 0
}