Skip to content

Commit 70fcb37

Browse files
author
Rujun Chen
authored
Fix concurrent problem in key vault certificates (Azure#22535)
1 parent 9db9597 commit 70fcb37

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

sdk/keyvault/azure-security-keyvault-jca/src/main/java/com/azure/security/keyvault/jca/KeyVaultCertificates.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,16 @@ public Map<String, Key> getCertificateKeys() {
131131
}
132132

133133
private void refreshCertificatesIfNeeded() {
134-
if (certificatesNeedRefresh()) {
134+
if (certificatesNeedRefresh()) { // Avoid acquiring the lock as much as possible.
135135
refreshCertificates();
136136
}
137137
}
138138

139-
private void refreshCertificates() {
139+
private synchronized void refreshCertificates() {
140+
if (!certificatesNeedRefresh()) {
141+
return; // After obtaining the lock, avoid doing too many operations.
142+
}
143+
// When refreshing certificates, the update of the 3 variables should be an atomic operation.
140144
aliases = keyVaultClient.getAliases();
141145
certificateKeys.clear();
142146
certificates.clear();

0 commit comments

Comments
 (0)