Fixed connection exhaustion causing DNS issues (#43402)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #42624

Fix for unreleased bug

## Testing
- [x] QA'd all new/changed functionality manually

For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **Bug Fixes**
* Adjusted certificate enrollment to process sequentially, ensuring
proper handling and reducing potential race conditions.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Victor Lyuboslavsky
2026-04-10 17:00:02 -04:00
committed by GitHub
parent 84a656fc29
commit e19ecaaf68
@@ -16,8 +16,6 @@ import java.time.Instant
import java.util.Date
import java.util.Locale
import java.util.TimeZone
import kotlinx.coroutines.async
import kotlinx.coroutines.coroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
@@ -822,7 +820,9 @@ class CertificateOrchestrator(
}
/**
* Enrolls multiple certificates in parallel.
* Enrolls multiple certificates sequentially. Each enrollment involves multiple HTTP calls
* (template fetch, SCEP enrollment, status update), so sequential processing avoids
* overwhelming the server and the device's network stack.
*
* @param context Android context for certificate installation
* @param hostCertificates List of certificate templates to enroll
@@ -832,14 +832,12 @@ class CertificateOrchestrator(
context: Context,
hostCertificates: List<HostCertificate>,
certificateInstaller: CertificateEnrollmentHandler.CertificateInstaller? = null,
): Map<Int, CertificateEnrollmentHandler.EnrollmentResult> = coroutineScope {
): Map<Int, CertificateEnrollmentHandler.EnrollmentResult> {
Log.d(TAG, "Starting batch certificate enrollment for ${hostCertificates.size} certificates")
hostCertificates.associate { cert ->
cert.id to async {
enrollCertificate(context, cert.id, cert.uuid, certificateInstaller)
}
}.mapValues { it.value.await() }
return hostCertificates.associate { cert ->
cert.id to enrollCertificate(context, cert.id, cert.uuid, certificateInstaller)
}
}
/**